How to use the @wasmer/wasi.WASI.defaultBindings function in @wasmer/wasi

To help you get started, we’ve selected a few @wasmer/wasi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wasmerio / wasmer-js / examples / wasm-shell / components / wasm-terminal.tsx View on Github external
// @ts-ignore
import WasmTerminal, {
  // @ts-ignore
  fetchCommandFromWAPM
  // @ts-ignore
} from "@wasmer/wasm-terminal";

import { WASI } from "@wasmer/wasi";
import BrowserWASIBindings from "@wasmer/wasi/bindings/browser";
// @ts-ignore
import { lowerI64Imports } from "@wasmer/wasm-transformer";

import welcomeMessage from "./welcome-message";
import { WasmFs } from "@wasmer/wasmfs";

WASI.defaultBindings = BrowserWASIBindings;

const commands = {
  callback: (options: any, wasmFs: any) => {
    let myArr = new Uint8Array(1024);
    let stdin = wasmFs.fs.readSync(0, myArr, 0, 1024, 0);
    return Promise.resolve(
      `Callback Command Working! Options: ${options}, stdin: ${myArr}`
    );
  }
};

let didInitWasmTransformer = false;
const fetchCommandHandler = async (
  commandName: string,
  commandArgs?: Array,
  envEntries?: any[][]
github wasmerio / wasmer-js / examples / wasm-shell / worker.ts View on Github external
import processWorker from "@wasmer/wasm-terminal/workers/process.worker";
import { WASI } from "@wasmer/wasi";
import BrowserWASIBindings from "@wasmer/wasi/bindings/browser";

WASI.defaultBindings = BrowserWASIBindings;

export default processWorker;
github wasmerio / wasmer-js / packages / wasm-terminal / src / command / wasi-command.ts View on Github external
async run(wasmFs: WasmFs) {
    const wasi = new WASI({
      preopens: {
        "/": "/"
      },
      env: this.options.env,
      args: this.options.args,
      bindings: {
        ...WASI.defaultBindings,
        fs: wasmFs.fs
      }
    });

    let instance = await WebAssembly.instantiate(
      this.options.module as WebAssembly.Module,
      {
        wasi_unstable: wasi.wasiImport
      }
    );
    wasi.start(instance);
  }
}

@wasmer/wasi

Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser.

MIT
Latest version published 2 years ago

Package Health Score

69 / 100
Full package analysis