mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-18 11:39:08 +00:00
Properly enforce ArrayBuffers for codec results
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
export interface Encoder {
|
export interface Encoder {
|
||||||
encode(data: ImageData): Promise<ArrayBuffer | SharedArrayBuffer>;
|
encode(data: ImageData): Promise<ArrayBuffer>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Decoder {
|
export interface Decoder {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export class MozJpegEncoder implements Encoder {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
async encode(data: ImageData): Promise<ArrayBuffer | SharedArrayBuffer> {
|
async encode(data: ImageData): Promise<ArrayBuffer> {
|
||||||
const m = await this.emscriptenModule;
|
const m = await this.emscriptenModule;
|
||||||
const api = await this.api;
|
const api = await this.api;
|
||||||
|
|
||||||
@@ -71,6 +71,7 @@ export class MozJpegEncoder implements Encoder {
|
|||||||
api.free_result();
|
api.free_result();
|
||||||
api.destroy_buffer(p);
|
api.destroy_buffer(p);
|
||||||
|
|
||||||
return result.buffer;
|
// wasm can’t run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
|
||||||
|
return result.buffer as ArrayBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user