Better error handling for libSquoosh

This commit is contained in:
Surma
2021-05-25 11:46:30 +01:00
parent f414092ea9
commit 99f2286a73
2 changed files with 28 additions and 14 deletions

View File

@@ -12,10 +12,13 @@ async function decodeFile({ file }) {
let buffer;
if (ArrayBuffer.isView(file)) {
buffer = Buffer.from(file.buffer);
file = 'Binary blob';
} else if (file instanceof ArrayBuffer) {
buffer = Buffer.from(file);
file = 'Binary blob';
} else if (file instanceof Buffer) {
buffer = file;
file = 'Binary blob';
} else if (typeof file === 'string') {
buffer = await fsp.readFile(file);
} else {
@@ -124,6 +127,7 @@ function handleJob(params) {
*/
class Image {
constructor(workerPool, file) {
this.file = file;
this.workerPool = workerPool;
this.decoded = workerPool.dispatchJob({ operation: 'decode', file });
this.encodedWith = {};