Skip to main content
@talosjs/fs wraps Bun’s file I/O behind two classes, File and Directory. Every operation is async and returns objects rather than raw paths. When something goes wrong, it throws a typed exception (FileException or DirectoryException) carrying a status code and contextual data.

Installation

Add the package with Bun:

Usage

Create a File from a path or URL, then read, write, or inspect it.

Streaming large files

Iterate over a file incrementally instead of loading it all into memory. streamAsJson reads a JSON array file and yields each element one at a time.

Downloading and buffered writing

Working with directories

Directory mirrors common shell operations and exposes async generators for traversal.

Good fits

This suits Bun projects that want an object-oriented layer over the file APIs, with descriptive errors (FileException, DirectoryException) carrying status codes and context instead of bare errno failures. It pays off most when you’re streaming large files through the generator helpers (stream, streamAsText, streamAsJson), or traversing, filtering, copying, moving, and watching directory trees where having File and Directory objects beats juggling path strings. For a trivial one-off read, Bun.file(...).text() is enough. And since the package targets Bun’s I/O, it isn’t meant for non-Bun runtimes.