diff --git a/libsquoosh/src/index.js b/libsquoosh/src/index.js index 93c1a895..dfd00cc4 100644 --- a/libsquoosh/src/index.js +++ b/libsquoosh/src/index.js @@ -9,7 +9,18 @@ import { autoOptimize } from './auto-optimizer.js'; export { ImagePool, encoders, preprocessors }; async function decodeFile({ file }) { - const buffer = await fsp.readFile(file); + let buffer; + if (ArrayBuffer.isView(file)) { + buffer = Buffer.from(file.buffer); + } else if (file instanceof ArrayBuffer) { + buffer = Buffer.from(file); + } else if (file instanceof Buffer) { + buffer = file; + } else if (typeof file === 'string') { + buffer = await fsp.readFile(file); + } else { + throw Error('Unexpected input type'); + } const firstChunk = buffer.slice(0, 16); const firstChunkString = Array.from(firstChunk) .map((v) => String.fromCodePoint(v))