Package Exports
- @kobakazu0429/wasmer-wasi
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kobakazu0429/wasmer-wasi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@wasmer/wasi
Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚
Documentation for Wasmer-JS Stack can be found on the Wasmer Docs.
Table of Contents
Features
@wasmer/wasi
uses the same API than the future WASI integration in Node, to help transition to it once it becomes available in Node.
However, @wasmer/wasi
is focused on:
- Bringing WASI to an Isomorphic context (Node.js and the Browser) 🖥️
- Make it easy to plug in different filesystems (via wasmfs) 📂
- Make it type-safe using Typescript 👷
- Pure JavaScript implementation (no Native bindings needed) 🚀
- ~ 15KB minified + gzipped 📦
Installation
For instaling @wasmer/wasi
, just run this command in your shell:
npm install --save @wasmer/wasi
Quick Start
This quick start is for browsers. For node, WasmFs is not required
import { WASI } from "@wasmer/wasi";
import { lowerI64Imports } from "@wasmer/wasm-transformer"
import { WasmFs } from "@wasmer/wasmfs";
// Instantiate a new WASI Instance
const wasmFs = new WasmFs();
let wasi = new WASI({
args: [],
env: {},
bindings: {
// uses browser APIs in the browser, node APIs in node
...WASI.defaultBindings,
fs: wasmFs.fs
}
});
const startWasiTask = async () => {
// Fetch our Wasm File
const response = await fetch("./my-wasi-module.wasm");
const responseArrayBuffer = await response.arrayBuffer();
// Instantiate the WebAssembly file
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer;
const lowered_wasm = await lowerI64Imports(wasm_bytes);
let module = await WebAssembly.compile(lowered_wasm);
let instance = await WebAssembly.instantiate(module, {
...wasi.getImports(module)
});
// Start the WebAssembly WASI instance!
wasi.start(instance);
// Output what's inside of /dev/stdout!
const stdout = await wasmFs.getStdOut();
console.log(stdout);
};
startWasiTask();
Reference API
The Reference API Documentation can be found on the @wasmer/wasi
Reference API Wasmer Docs.
Contributing
This project follows the all-contributors specification.
Contributions of any kind are welcome! 👍