Skip to main content

File System Library (fs)

fs needs the system feature flag, which means real disk access — not something this browser-based sandbox has wired up, so every example below is reference only, not runnable here. (It's possible to expose a scoped version of this to a browser host — this site's separate live playground does exactly that — just not something this docs site does yet.) If you're building something that should never touch the filesystem at all, the flip side is just as easy: leave fs out of the host's loaded libraries entirely, and a document simply can't reach for it.

fs.read(path: str) -> blob

Reads a file into a binary blob.

const bytes = fs.read("src/lib.rs");

fs.read_string(path: str) -> str

Same as fs.read, but as a string instead of raw bytes.

const content = fs.read_string("src/lib.rs");

fs.write(path: str, content: str | blob) -> void

Writes to a file, overwriting it if it already exists. Throws if the containing directory doesn't exist.

fs.write("src/text.txt", "testing");