From 3c662cccfe3157cea9f1497d804df2b9ea85668d Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 19 Oct 2021 15:24:44 +0200 Subject: [PATCH] feat: support `createStreaming` in Deno (#4) --- mod.ts | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/mod.ts b/mod.ts index a852077..21db6a2 100644 --- a/mod.ts +++ b/mod.ts @@ -97,40 +97,9 @@ export function createImportObject(): WebAssembly.Imports { export function createStreaming( response: Promise, ): Promise { - // instantiateStreaming is not working in Deno (issue #309) and in newer versions - // it no longer exists on the `WebAssembly` object, so use an `any` type here. - if ( - // deno-lint-ignore no-explicit-any - (WebAssembly as any).instantiateStreaming == null - // deno-shim-ignore - || typeof globalThis?.Deno != null - ) { - return getArrayBuffer() - .then((buffer) => createFromBuffer(buffer)); - } else { - // deno-lint-ignore no-explicit-any - return (WebAssembly as any) - .instantiateStreaming( - response, - createImportObject(), - ) - .then(( - // deno-lint-ignore no-explicit-any - obj: any, - ) => createFromInstance(obj.instance)); - } - - function getArrayBuffer() { - if (isResponse(response)) { - return response.arrayBuffer(); - } else { - return response.then((response) => response.arrayBuffer()); - } - - function isResponse(response: unknown): response is Response { - return (response as Response).arrayBuffer != null; - } - } + return WebAssembly + .instantiateStreaming(response,createImportObject()) + .then((obj) => createFromInstance(obj.instance)); } /**