@ooneex/fs wraps Bun’s optimized file I/O behind two ergonomic classes, File and Directory. Every operation is async, returns rich objects instead of raw paths, and throws typed exceptions (FileException, DirectoryException) carrying a status code and contextual data when something goes wrong.
Installation
Add the package with Bun:Usage
Create aFile 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.
When to use it
- You are building on Bun and want a clean, object-oriented wrapper around its file APIs.
- You need typed, descriptive errors (
FileException/DirectoryException) with status codes and context instead of rawerrnofailures. - You process large files and want generator-based streaming (
stream,streamAsText,streamAsJson). - You traverse, filter, copy, move, or watch directory trees and want
File/Directoryobjects rather than bare strings. - Skip it for trivial one-off reads where
Bun.file(...).text()is enough, or in non-Bun runtimes (the package targets Bun’s I/O).