Properly enforce ArrayBuffers for codec results

This commit is contained in:
Surma
2018-05-23 11:09:35 +02:00
parent 638c57b6fe
commit e62fc26dfd
2 changed files with 4 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
export interface Encoder {
encode(data: ImageData): Promise<ArrayBuffer | SharedArrayBuffer>;
encode(data: ImageData): Promise<ArrayBuffer>;
}
export interface Decoder {

View File

@@ -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 api = await this.api;
@@ -71,6 +71,7 @@ export class MozJpegEncoder implements Encoder {
api.free_result();
api.destroy_buffer(p);
return result.buffer;
// wasm cant run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
return result.buffer as ArrayBuffer;
}
}