Reading & Writing Files in Bun
From the Bun cheat sheet ยท File I/O ยท verified Jul 2026
Reading & Writing Files
Fast file operations with Bun.file() and Bun.write()
typescript
// Read a file
const file = Bun.file("data.json");
const text = await file.text();
const json = await file.json();
// Write a file
await Bun.write("output.txt", "Hello World");
await Bun.write("data.json", JSON.stringify({ ok: true }));๐ก Bun.file() is lazy โ it only reads from disk when you call .text(), .json(), etc.
โก Bun.write() is 10x faster than Node fs.writeFileSync โ uses optimized system calls
๐ Pass a Bun.file() or fetch Response directly to Bun.write() for zero-copy operations
๐ข Use file.writer() for incremental writes like logging โ flush() ensures data persists
filereadwriteio