How to use the @wasmer/wasi.WASI 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 / packages / cli / src / commands / run.ts View on Github external
}
    let wasiArgs = this.argv.filter((arg: string) => {
      if (arg.startsWith("--dir")) {
        return false;
      }
      return true;
    });
    // wasiArgs = [`wasmer-js run ${wasiArgs[0]}`, ...wasiArgs.splice(1)];

    // If we find a `--`, we try to get only the arguments after
    const indexLimit = wasiArgs.indexOf("--");
    if (indexLimit > 0) {
      wasiArgs = [wasiArgs[0], ...wasiArgs.splice(indexLimit + 1)];
    }

    const wasi = new WASI({
      args: wasiArgs,
      bindings: {
        ...nodeBindings,
        fs
      },
      env: {},
      preopens
    });

    const wasmBytes = fs.readFileSync(args.file);
    const transformedBytes = await lowerI64Imports(wasmBytes);
    const { instance } = await WebAssembly.instantiate(transformedBytes, {
      wasi_unstable: wasi.wasiImport
    });
    wasi.start(instance);
  }
github DigitalArsenal / openssl.js / src / command.js View on Github external
/**
 * ECMAScript Interface to WASM port of OpenSSL (https://www.openssl.org)
 * @module OpenSSL
 * 
 * @license Apache-2.0
 * @copyright 2019 DIGITALARSENAL.IO, INC.
 */

import _WASI from "@wasmer/wasi";
const WASI = isNode ? _WASI.WASI : _WASI; //module issue
import { isNode } from "./isNode.js";

export const run = async args => {
  let _filename;
  try {
    _filename = __filename
  } catch (e) {

  }
  if (isNode && !_filename) {
    const { fileURLToPath } = await import("url"); //SyntaxError: Parenthesized pattern ({fileURLToPath})
    _filename = fileURLToPath(import.meta.url);
  }

  let command = ["openssl"].concat(
    args.command.split(/[\s]{1,}/g).filter(Boolean)
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
      }

@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