How to use the bindings/wasi.fd_write function in bindings

To help you get started, we’ve selected a few bindings 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 jedisct1 / as-wasi / assembly / wasa.ts View on Github external
static writeStringLn(fd: Descriptor, s: string): void {
    let s_utf8_len: usize = s.lengthUTF8 - 1;
    let s_utf8 = s.toUTF8();
    let iov = changetype(new ArrayBuffer(4 * sizeof()));
    store(iov, s_utf8);
    store(iov + sizeof(), s_utf8_len);
    let lf = changetype(new ArrayBuffer(1));
    store(lf, 10);
    store(iov + sizeof() * 2, lf);
    store(iov + sizeof() * 3, 1);
    let written_ptr = changetype(new ArrayBuffer(sizeof()));
    fd_write(fd, iov, 2, written_ptr);
  }
github jedisct1 / as-wasi / assembly / wasa.ts View on Github external
static write(fd: Descriptor, data: Array): void {
    let data_buf_len = data.length;
    let data_buf = changetype(new ArrayBuffer(data_buf_len));
    for (let i = 0; i < data_buf_len; i++) {
      store(data_buf + i, unchecked(data[i]));
    }
    let iov = changetype(new ArrayBuffer(2 * sizeof()));
    store(iov, data_buf);
    store(iov + sizeof(), data_buf_len);

    let written_ptr = changetype(new ArrayBuffer(sizeof()));
    fd_write(fd, iov, 1, written_ptr);
  }
github jedisct1 / as-wasi / assembly / wasa.ts View on Github external
static writeString(fd: Descriptor, s: string, newline: bool = false): void {
    if (newline) {
      this.writeStringLn(fd, s);
      return;
    }
    let s_utf8_len: usize = s.lengthUTF8 - 1;
    let s_utf8 = s.toUTF8();
    let iov = changetype(new ArrayBuffer(2 * sizeof()));
    store(iov, s_utf8);
    store(iov + sizeof(), s_utf8_len);
    let written_ptr = changetype(new ArrayBuffer(sizeof()));
    fd_write(fd, iov, 1, written_ptr);
  }