@kobakazu0429/wasmer-wasi
v0.12.0-internal
Published
Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. ๐
Downloads
18
Maintainers
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! ๐