Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ import { WasmFs } from "@wasmer/wasmfs";
const swift = new SwiftRuntime();
// Instantiate a new WASI Instance
const wasmFs = new WasmFs();

// Output stdout and stderr to console
const originalWriteSync = wasmFs.fs.writeSync;
wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => {
const text = new TextDecoder("utf-8").decode(buffer);

// Filter out standalone "\n" added by every `print`, `console.log`
// always adds its own "\n" on top.
if (text !== "\n") {
switch (fd) {
case 1:
console.log(text);
break;
case 2:
console.error(text);
break;
}
}
return originalWriteSync(fd, buffer, offset, length, position);
};

let wasi = new WASI({
args: [],
env: {},
Expand All @@ -30,9 +51,5 @@ const startWasiTask = async () => {
swift.setInstance(instance);
// Start the WebAssembly WASI instance!
wasi.start(instance);

// Output what's inside of /dev/stdout!
const stdout = await wasmFs.getStdOut();
console.log(stdout);
};
startWasiTask();