From ccb9102bf1c1a802e0473fa110ad43422b1d9667 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Mon, 24 Feb 2025 10:29:24 +0900 Subject: [PATCH 1/2] test: add doAppendAndCancel test --- ...est-fs-promises-file-handle-append-file.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-fs-promises-file-handle-append-file.js b/test/parallel/test-fs-promises-file-handle-append-file.js index 90bb6e392516f4..42b6dbee309cec 100644 --- a/test/parallel/test-fs-promises-file-handle-append-file.js +++ b/test/parallel/test-fs-promises-file-handle-append-file.js @@ -39,6 +39,21 @@ async function validateAppendString() { await fileHandle.close(); } -validateAppendBuffer() - .then(validateAppendString) - .then(common.mustCall()); +async function doAppendAndCancel() { + const filePathForHandle = path.resolve(tmpDir, 'dogs-running.txt'); + const fileHandle = await open(filePathForHandle, 'w+'); + const buffer = Buffer.from('dogs running'.repeat(512 * 1024), 'utf8'); + const controller = new AbortController(); + const { signal } = controller; + process.nextTick(() => controller.abort()); + await assert.rejects(fileHandle.appendFile(buffer, { signal }), { + name: 'AbortError' + }); + await fileHandle.close(); +} + +Promise.all([ + validateAppendBuffer(), + validateAppendString(), + doAppendAndCancel(), +]).then(common.mustCall()); From 20fdc9921428ac6d94618257fc651f9c75b7b024 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Mon, 24 Feb 2025 10:29:31 +0900 Subject: [PATCH 2/2] doc: update options to filehandle.appendFile() --- doc/api/fs.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 3b0fa6416d4674..513da01186ce1e 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -199,8 +199,7 @@ changes: * `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream} * `options` {Object|string} * `encoding` {string|null} **Default:** `'utf8'` - * `flush` {boolean} If `true`, the underlying file descriptor is flushed - prior to closing it. **Default:** `false`. + * `signal` {AbortSignal|undefined} allows aborting an in-progress writeFile. **Default:** `undefined` * Returns: {Promise} Fulfills with `undefined` upon success. Alias of [`filehandle.writeFile()`][].