File I/O Operations
Bun provides fast file system operations through the Bun.file() and Bun.write() APIs. These are significantly faster than Node.js equivalents.
Reading Files with Bun.file()
Bun.file() creates a lazy reference to a file:
Loading Bun Playground...
Reading Different Formats
Files can be read as text, JSON, or binary:
Loading Bun Playground...
Writing Files with Bun.write()
Bun.write() is extremely fast for writing data:
Loading Bun Playground...
File Copying
Bun.write can copy files efficiently:
Loading Bun Playground...
Working with Directories
Loading Bun Playground...
Exercise: File Size Calculator
Create a function that calculates the total size of multiple files:
Loading Bun Exercise...
Exercise: JSON File Manager
Create functions to read and write JSON files:
Loading Bun Exercise...
Exercise: File Content Search
Create a function that searches file content:
Loading Bun Exercise...

