Skip to main content
Bun provides an API for incrementally writing to a file. Use it for large files, or when writing to a file over a long period of time. Call .writer() on a BunFile to retrieve a FileSink instance. It buffers data; call .flush() to write the buffer to disk. You can write & flush many times.

The .write() method accepts strings or binary data.

The FileSink also auto-flushes when its internal buffer is full.
When you’re done writing, call .end() to flush the buffer and close the file.

Full documentation: FileSink.