node:fs
| Imports | Implementation |
|---|---|
node:fs, node:fs/promises | @bytecodealliance/jco-std/wasi/0.2.x/node/24.x.x/fs |
By default, node:fs and node:fs/promises use one jco:node/fs@0.1.0 host capability.
When either specifier occurs in bundled source, Jco adds a missing import to the
selected world, installs fs.wit under deps/jco-node-0.1.0, and prints a CLI
warning to alert to the fact that a WIT dependency has been added.
The default filesystem host provider returns a typed denial result, which the
guest reconstructs as ERR_JCO_FS_ADAPTER_REQUIRED.
To use the passthrough NodeJS host provider you can map it in:
jco transpile component.wasm \
--map 'jco:node/fs@0.1.0=@bytecodealliance/jco-std/wasi/0.2.x/node/24.x.x/fs/host/node'
To use a WASI Preview 2 host, build with --bundle --with-nodejs-vfs-via wasi-filesystem.
Jco bundles the filesystem provider into the guest. Both modules share one descriptor table
and resolve paths against the host’s preopened directories. Relative paths use the guest’s
initial working directory, falling back to / when it is unspecified. See the
Wasmtime example.
The WASI provider supports file reads, writes, directory operations, links and metadata.
Use cp and rm for recursive copy and removal, glob for pattern matching,
and mkdtemp to create a temporary directory.
The host sets permissions on newly created files and directories, including temporary directories.
WASI 0.2.12 exposes no way to change file permissions or ownership or query filesystem-wide
statistics, so chmod, chown and statfs are unavailable.
The direct Node provider uses the following call path.
- guest
node:fs - WIT capability
- host adapter
- NodeJS builtins
The Node provider delegates to Node 24’s synchronous operations; guest callback APIs
queue their callbacks on a microtask, and promise APIs share the same descriptor
state through promise FileHandles.
Common file and directory operations, metadata, directory entries, scalar and vector descriptor I/O, and their callback/promise facades are supported.
Warning
APIs whose contract requires long-lived streams or event sources are not yet supported – including
ReadStream,WriteStream,Utf8Stream,watch,watchFile, andopenAsBlob.These functions currently throw
ERR_JCO_UNSUPPORTED_NODE_APIbecause the typed WIT interface does not model those resources.