bun-file-io

Perform file reading, writing, streaming, and glob operations with Bun APIs.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aicodepro/ai-agent-nexi --skill bun-file-io-aicodepro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bun-file-io
Source: https://github.com/aicodepro/ai-agent-nexi/tree/main/agent/skills/bun-file-io
Command: npx skills add https://github.com/aicodepro/ai-agent-nexi --skill bun-file-io-aicodepro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Working with files in Bun requires knowing which API to use for each scenario—Bun.file versus node:fs, streaming versus buffering, glob matching versus manual directory traversal. This Skill consolidates the correct patterns for every common file I/O task in Bun so you avoid trial and error. ## Core Features & Use Cases - File Reading and Writing: Use Bun.file() for lazy file references with text, JSON, and binary reads, and Bun.write() for strings, binary data, HTTP responses, and file-to-file copies. - Streaming and Directories: Process large files with readable/writable streams, pipe through TransformStreams, and manage directories with node:fs/promises and Bun.Glob pattern matching. - Use Case: Imagine you need to download images from an API, save them to disk, then scan a source directory for all TypeScript files. This Skill shows you to pipe the fetch response directly to Bun.write() and iterate matches with Bun.Glob's scan(). ## Quick Start Ask the assistant to write a Bun script that reads a JSON config file, transforms its contents, and writes the result to a new file using Bun.file and Bun.write.

Frequently Asked Questions about bun-file-io

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I read and write files in Bun?

Use Bun.file(path) to create a lazy file reference, then call .text(), .json(), or .arrayBuffer() to read. Write with Bun.write(path, data), which accepts strings, binary data, fetch responses, or other Bun.file references for efficient copies.

How to append to a file in Bun?

Create a writer with Bun.file(path).writer(), call writer.write() for each chunk, then flush and end. Alternatively, use appendFile from node:fs/promises, which Bun fully supports.

Does Bun support glob pattern matching for files?

Yes, Bun.Glob scans directories with patterns like **/*.ts and supports options for dotfiles, absolute paths, and files-only results. Iterate matches with for await on glob.scan() or test single paths with pattern.match().

Can I use node:fs modules with Bun?

Bun implements the node:fs and node:fs/promises APIs, so readdir, mkdir, stat, appendFile, and watch all work. Bun-native APIs like Bun.file and Bun.write are typically faster for common operations.

Why does Bun.file not throw when a file is missing?

Bun.file() creates a lazy reference without touching the disk, so no error occurs at creation. Check await file.exists() before reading, or handle ENOENT errors when calling read methods.