From d1aa62f1f5462443a5123466d49811b592ed275a Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Wed, 11 Oct 2023 12:25:05 -0400 Subject: [PATCH] fs: add flush option to createWriteStream() This commit adds a 'flush' option to the createWriteStream() family of functions. Refs: https://github.com/nodejs/node/issues/49886 PR-URL: https://github.com/nodejs/node/pull/50093 Reviewed-By: Yagiz Nizipli Reviewed-By: Matteo Collina Reviewed-By: Marco Ippolito --- doc/api/fs.md | 11 +++ lib/fs.js | 1 + lib/internal/fs/promises.js | 1 + lib/internal/fs/streams.js | 28 ++++++- test/parallel/test-fs-write-stream-flush.js | 81 +++++++++++++++++++++ 5 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-fs-write-stream-flush.js diff --git a/doc/api/fs.md b/doc/api/fs.md index b15c7be1d1f192..8442fa2a5a18b4 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -318,6 +318,10 @@ fd.createReadStream({ start: 90, end: 99 }); * `options` {Object} @@ -326,6 +330,8 @@ added: v16.11.0 * `emitClose` {boolean} **Default:** `true` * `start` {integer} * `highWaterMark` {number} **Default:** `16384` + * `flush` {boolean} If `true`, the underlying file descriptor is flushed + prior to closing it. **Default:** `false`. * Returns: {fs.WriteStream} `options` may also include a `start` option to allow writing data at some @@ -2514,6 +2520,9 @@ If `options` is a string, then it specifies the encoding.