--- name: Write a file incrementally --- Bun provides an API for incrementally writing to a file. This is useful for writing large files, or for writing to a file over a long period of time. Call `.writer()` on a `BunFile` to retrieve a `FileSink` instance. This instance can be used to efficiently buffer data and periodically "flush" it to disk. You can write & flush many times. ```ts const file = Bun.file("/path/to/file.txt"); const writer = file.writer(); writer.write("lorem"); writer.write("ipsum"); writer.write("dolor"); writer.flush(); // continue writing & flushing ``` --- The `.write()` method can accept strings or binary data. ```ts w.write("hello"); w.write(Buffer.from("there")); w.write(new Uint8Array([0, 255, 128])); writer.flush(); ``` --- The `FileSink` will also auto-flush when its internal buffer is full. You can configure the buffer size with the `highWaterMark` option. ```ts const file = Bun.file("/path/to/file.txt"); const writer = file.writer({ highWaterMark: 1024 * 1024 }); // 1MB ``` --- When you're done writing to the file, call `.end()` to auto-flush the buffer and close the file. ```ts writer.end(); ``` --- Full documentation: [FileSink](/docs/api/file-io#incremental-writing-with-filesink). ock Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/src/resolver (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-04-02Add more typingsGravatar Jarred Sumner 1-2/+416
2022-04-02Add more tests for Node FSGravatar Jarred Sumner 4-1/+60
2022-04-02[bun.js] fs.readSync & fs.writeSync should return just the numberGravatar Jarred Sumner 1-24/+57
2022-04-02[bun.js] Support `mode` and `flags` as integer args in fs.openSync (instead o...Gravatar Jarred Sumner 1-0/+6
2022-04-02Update base.zigGravatar Jarred Sumner 1-0/+1
2022-04-02Fix GC bug when reading TypedArray from user inputGravatar Jarred Sumner 1-6/+36
2022-04-02s/Buffer/TypedArrayGravatar Jarred Sumner 1-17/+17
2022-04-02Fix mmap on macOS x64Gravatar Jarred Sumner 2-29/+27