wasm-instantiate-streaming
v1.0.2
Published
Ponyfill of WebAssembly.instantiateStreaming
Downloads
156
Maintainers
Readme
wasm-instantiate-streaming
Polyfill of WebAssembly.instantiateStreaming
instantiateStreaming
loading WebAssembly modules efficiently
The optimizations we applied can be summarized as follows:
- Use asynchronous APIs to avoid blocking the main thread
- Use streaming APIs to compile and instantiate WebAssembly modules more quickly
- Don’t write code you don’t need
— Loading WebAssembly modules efficiently | Web | Google Developers
Install
npm install wasm-instantiate-streaming
Usage
Using import/require
import { instantiateStreaming } from 'wasm-instantiate-streaming'
// For browser
instantiateStreaming(fetch('some-module.wasm'))
// Use with node-fetch
const fetch = require('node-fetch')
instantiateStreaming(fetch('some-module.wasm'))
// Use with fs module
const fs = require('fs')
const { promisify } = require('util')
const readFile = promisify(fs.readFile)
instantiateStreaming(readFile('./some-module.wasm'))
Using without import/require
Please use build/browser.min.js
<script src="path/to/build/browser.min.js">
instantiateStreaming(fetch('some-module.wasm'))
Pass importsObject
const importObject = {
imports: {
imported_func (arg) {
console.log(arg)
}
}
}
instantiateStreaming(fetch('some-module.wasm'), importObject)
API
See MDN document
Development
git clone [email protected]:Leko/wasm-instantiate-streaming.git
cd wasm-instantiate-streaming
git submodule update --init --recursive
cd deps/wabt
make
cd ../..
npm install
npm test