nodejs / uvwasi

WASI syscall API built atop libuv
MIT License
226 stars 51 forks source link

The result `read_link` is followed by an extra \0 #262

Closed Brooooooklyn closed 5 months ago

Brooooooklyn commented 5 months ago

Source code

use std::fs::read_link;

fn main() {
    let link = read_link("./link.txt").unwrap();
    println!("{:?}", link);
}
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { WASI } from 'node:wasi'

const wasi = new WASI({
  preopens: {
    '/': join(fileURLToPath(import.meta.url), '..'),
  },
  version: 'preview1',
  env: process.env,
})

const wasm = await WebAssembly.compile(
  await readFile(new URL('./target/wasm32-wasi/debug/wasi-read-link.wasm', import.meta.url))
)

const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject())

wasi.start(instance)

wasmtime run --dir $(pwd)::/ target/wasm32-wasi/debug/wasi-read-link.wasm

node index.mjs

image