Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hazae41
committed
Jun 26, 2020
1 parent
d2e4564
commit cbf75bb
Showing
1 changed file
with
10 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |