forked from external-repos/squoosh
Remove Buffer from decodeFile()
This commit is contained in:
@@ -14,13 +14,8 @@ async function decodeFile({
|
|||||||
}: {
|
}: {
|
||||||
file: ArrayBuffer;
|
file: ArrayBuffer;
|
||||||
}): Promise<{ bitmap: ImageData; size: number }> {
|
}): Promise<{ bitmap: ImageData; size: number }> {
|
||||||
let buffer: Buffer;
|
const array = new Uint8Array(file);
|
||||||
if (file instanceof ArrayBuffer) {
|
const firstChunk = array.slice(0, 16);
|
||||||
buffer = Buffer.from(file);
|
|
||||||
} else {
|
|
||||||
throw Error('Unexpected input type');
|
|
||||||
}
|
|
||||||
const firstChunk = buffer.slice(0, 16);
|
|
||||||
const firstChunkString = Array.from(firstChunk)
|
const firstChunkString = Array.from(firstChunk)
|
||||||
.map((v) => String.fromCodePoint(v))
|
.map((v) => String.fromCodePoint(v))
|
||||||
.join('');
|
.join('');
|
||||||
@@ -32,10 +27,10 @@ async function decodeFile({
|
|||||||
}
|
}
|
||||||
const encoder = encoders[key];
|
const encoder = encoders[key];
|
||||||
const mod = await encoder.dec();
|
const mod = await encoder.dec();
|
||||||
const rgba = mod.decode(new Uint8Array(buffer));
|
const rgba = mod.decode(array);
|
||||||
return {
|
return {
|
||||||
bitmap: rgba,
|
bitmap: rgba,
|
||||||
size: buffer.length,
|
size: array.length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user