kawamuray / wasmtime-java

Java or JVM-language binding for Wasmtime
Apache License 2.0
127 stars 29 forks source link

Wasi context stdin truncate file if exist, with no ability writing to it #54

Open amysyk-viax-io opened 10 months ago

amysyk-viax-io commented 10 months ago

Is there a way to pass data into stdin via wasi context?

When file already exist it will be truncated during wasi context creation

final var stdinPath = Paths.get("./wasm/io/stdin.txt");

Files.writeString(stdinPath, "{\"name\": \"John\"}");

final var wasi = new WasiCtxBuilder()
        .stdin(stdinPath)
        .build();

Another case, when trying to write data after context creation it is ignored

final var stdinPath = Paths.get("./wasm/io/stdin.txt");
final var wasi = new WasiCtxBuilder()
        .stdin(stdinPath)
        .build();

Files.writeString(stdinPath, "{\"name\": \"John\"}");

You can find full working example here: https://github.com/amysyk-viax-io/wasmtime-java-stdin-stdout