Remove Buffer from decodeFile()

This commit is contained in:
Steven
2021-08-20 18:36:23 -04:00
parent 30140c2b7a
commit bdb5b16372

View File

@@ -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,
}; };
} }