--- 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). cess-fixes Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/src/node-fallbacks/buffer.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-02-24[bun install] Add integration test for bin linksGravatar Jarred Sumner 1-1/+7
2022-02-24Add WASM modules but disable it for nowGravatar Jarred Sumner 28-134/+530
2022-02-24bump build idGravatar Jarred Sumner 1-1/+1
2022-02-24fix test failure in path.resolveGravatar Jarred Sumner 1-2/+6
2022-02-24Ensure we run the process testGravatar Jarred Sumner 2-48/+54
2022-02-24Update javascript.zigGravatar Jarred Sumner 1-1/+110
2022-02-24[bun.js] Add `ShadowRealm`Gravatar Jarred Sumner 7-18/+70
2022-02-24[bun-framework-next] Remove TextEncoder & TextDecoder polyfillsGravatar Jarred Sumner 3-340/+19
2022-02-24Use a JSFinalobject for PathGravatar Jarred Sumner 2-81/+42
2022-02-24Expose TextEncoder & TextDecoder globallyGravatar Jarred Sumner 3-20/+750
2022-02-24[Web Platform] Implement TextEncoder & TextDecoderGravatar Jarred Sumner 12-358/+1044
2022-02-24move GCDeferralContextGravatar Jarred Sumner 2-18/+24
2022-02-24[JS Parser] ensure assertions are never run at runtimeGravatar Jarred Sumner 1-13/+18
2022-02-24misc cleanupGravatar Jarred Sumner 2-7/+18
2022-02-22Make format consistent with WebKitGravatar Jarred Sumner 20-3596/+4110
2022-02-22import assertion testGravatar Jarred Sumner 1-0/+33
2022-02-22snaspshotsGravatar Jarred Sumner 42-94/+113