0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

docs: Document the WASM streaming APIs. (#11430)

This commit is contained in:
Andreu Botella 2021-07-18 00:26:11 +02:00 committed by GitHub
parent 240545282a
commit 03ba63e108
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,7 +21,7 @@ const main = wasmInstance.exports.main as CallableFunction
console.log(main().toString());
```
And for files:
For files:
```ts
const wasmCode = await Deno.readFile("main.wasm");
@ -30,3 +30,14 @@ const wasmInstance = new WebAssembly.Instance(wasmModule);
const main = wasmInstance.exports.main as CallableFunction;
console.log(main().toString());
```
And for loading WebAssembly modules over the network (note that the file must be
served with `application/wasm` MIME type):
```ts
const { instance, module } = await WebAssembly.instantiateStreaming(
fetch("https://wpt.live/wasm/incrementer.wasm"),
);
const increment = instance.exports.increment as (input: number) => number;
console.log(increment(41));
```