Skip to content

Commit

Permalink
fix(filesystem): Don't call toString on binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacivita committed Jun 6, 2023
1 parent cd79adc commit 42746a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/shared/filesystem.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const readDir = async (ref, options) => {
return results.sort()
}

const binFormats = [ '.png', '.jpg', '.gif' ]

const readFiles = (refs, base) => Promise.all(refs.map(ref => readFile(ref)))
.then(contents => {
if (!refs || refs.length === 0) {
Expand All @@ -63,7 +65,12 @@ const readFiles = (refs, base) => Promise.all(refs.map(ref => readFile(ref)))

const results = refs.map(v => [v.substring(index), null])
for (let i=0; i<refs.length; i++) {
results[i][1] = contents[i].toString()
if (binFormats.find(suffix => refs[i].endsWith(suffix))) {
results[i][1] = contents[i]
}
else {
results[i][1] = contents[i].toString()
}
}
return Promise.resolve(Object.fromEntries(results))
})
Expand Down

0 comments on commit 42746a1

Please sign in to comment.