Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed Jun 26, 2020
1 parent d2e4564 commit cbf75bb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion wasm.ts
@@ -1,7 +1,16 @@
export async function Wasm(path: string) {
const url = new URL(`./pkg/${path}`, import.meta.url);
const code = await Deno.readFile(url);
const code = await read(url);
const module = new WebAssembly.Module(code);
const instance = new WebAssembly.Instance(module);
return instance.exports;
}

async function read(url: URL) {
if (url.protocol === "file:") {
return await Deno.readFile(url);
}

const response = await fetch(url);
return await response.arrayBuffer();
}

0 comments on commit cbf75bb

Please sign in to comment.