From 202d0bc088fa41ab3dae47da9123bceeee831259 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 20 Aug 2021 18:48:30 -0400 Subject: [PATCH] Generalize file to ArrayLike --- libsquoosh/src/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libsquoosh/src/index.ts b/libsquoosh/src/index.ts index 51844378..2e1c8f5c 100644 --- a/libsquoosh/src/index.ts +++ b/libsquoosh/src/index.ts @@ -12,7 +12,7 @@ type PreprocessorKey = keyof typeof preprocessors; async function decodeFile({ file, }: { - file: ArrayBuffer; + file: ArrayBuffer | ArrayLike; }): Promise<{ bitmap: ImageData; size: number }> { const array = new Uint8Array(file); const firstChunk = array.slice(0, 16); @@ -151,12 +151,15 @@ function handleJob(params: JobMessage) { * Represents an ingested image. */ class Image { - public file: ArrayBuffer; + public file: ArrayBuffer | ArrayLike; public workerPool: WorkerPool; public decoded: Promise<{ bitmap: ImageData }>; public encodedWith: { [key: string]: any }; - constructor(workerPool: WorkerPool, file: ArrayBuffer) { + constructor( + workerPool: WorkerPool, + file: ArrayBuffer | ArrayLike, + ) { this.file = file; this.workerPool = workerPool; this.decoded = workerPool.dispatchJob({ operation: 'decode', file }); @@ -244,10 +247,10 @@ class ImagePool { /** * Ingest an image into the image pool. - * @param {ArrayBuffer} file - The image that should be ingested and decoded. + * @param {ArrayBuffer | ArrayLike} file - The image that should be ingested and decoded. * @returns {Image} - A custom class reference to the decoded image. */ - ingestImage(file: ArrayBuffer): Image { + ingestImage(file: ArrayBuffer | ArrayLike): Image { return new Image(this.workerPool, file); }