@wasmer/wasi
The Package for using WASI easily from Node and the Browser
import { WASI } from "@wasmer/wasi"
new WASI(wasiConfigObject): WASI
Constructs a new WASI instance.
The
wasiConfigObject
is as follows:const browserBindings = require("@wasmer/wasi/lib/bindings/browser");
// for Node:
// const nodeBindings = require("@wasmer/wasi/lib/bindings/node");
let myWASIInstance = new WASI({
// OPTIONAL: The pre-opened dirctories
preopenDirectories: {},
// OPTIONAL: The environment vars
env: {},
// OPTIONAL: The arguments provided
args: [],
// OPTIONAL: The environment bindings (fs, path),
// useful for using WASI in diferent environments
// such as Node.js, Browsers, ...
bindings: {
// hrtime: (time?: [number, number]) -> number
// exit: (code?: number) -> void
// kill: (pid: number, signal?: string | number) -> void
// randomFillSync: (buffer: Buffer, offset?: number, size?: number) -> Buffer
// isTTY: () -> bool
// fs: Filesystem (with similar API interface as Node 'fs' module)
// path: Path (with similar API Interface as Node 'path' module)
...browserBindings // Use `nodeBindings` for Node
}
});
This returns a WASI instance. Please see the Instance properties section to learn about the WASI instance.
wasiInstance.memory: WebAssembly.Memory
wasiInstance.view: DataView
wasiInstance.FD_MAP: Map<number, File>
wasiInstance.exports: Exports
WASI API to be imported in the importObject on instantiation.
wasiInstance.bindings: WASIBindings
The bindings for common node like objects, such as
fs
for filesystem, these should work by default, but are applied depending on the platform. You can view the source code for your respective platform's bindings here.wasiInstance.start(wasmInstance: WebAssembly.Instance): void
Function that takes in a WASI WebAssembly Instance and starts it.
wasiInstance.getImports(wasmModule: WebAssembly.Module): Exports
Function that returns the map of corresponding imports for the WASI module. It will throw an error in case the
wasmModule
is not a WASI Module, or it have an incompatible version.Last modified 1yr ago