wasm-instantiate-streaming

1.0.2 • Public • Published

wasm-instantiate-streaming

package-version node-version CircleCI codecov license

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

WebAssembly.instantiateStreaming() - JavaScript | MDN

Development

git clone git@github.com:Leko/wasm-instantiate-streaming.git
cd wasm-instantiate-streaming
 
git submodule update --init --recursive
cd deps/wabt
make
cd ../..
 
npm install
npm test

License

MIT

Package Sidebar

Install

npm i wasm-instantiate-streaming

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

9.53 kB

Total Files

6

Last publish

Collaborators

  • lekoleko