From 0fd121e00c9d5987c20c27a4ee4295da7735d9de Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Mon, 2 Nov 2020 13:10:36 +0100 Subject: [PATCH] stream: add FileHandle support to Read/WriteStream Support creating a Read/WriteStream from a FileHandle instead of a raw file descriptor Add an EventEmitter to FileHandle with a single 'close' event. Fixes: https://github.com/nodejs/node/issues/35240 PR-URL: https://github.com/nodejs/node/pull/35922 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- doc/api/fs.md | 20 +++++- lib/internal/event_target.js | 17 +++++ lib/internal/fs/promises.js | 38 +++++++---- lib/internal/fs/streams.js | 68 ++++++++++++++++++- ...est-fs-promises-file-handle-read-worker.js | 50 ++++++++++++++ .../test-fs-promises-file-handle-read.js | 47 +++++++------ .../test-fs-read-stream-file-handle.js | 65 ++++++++++++++++++ .../test-fs-write-stream-file-handle.js | 21 ++++++ 8 files changed, 285 insertions(+), 41 deletions(-) create mode 100644 test/parallel/test-fs-promises-file-handle-read-worker.js create mode 100644 test/parallel/test-fs-read-stream-file-handle.js create mode 100644 test/parallel/test-fs-write-stream-file-handle.js diff --git a/doc/api/fs.md b/doc/api/fs.md index 84bdf4894b0e4e..7411135e0b3def 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1761,6 +1761,10 @@ fs.copyFileSync('source.txt', 'destination.txt', COPYFILE_EXCL); + +The `'close'` event is emitted when the `FileHandle` and any of its underlying +resources (a file descriptor, for example) have been closed. + #### `filehandle.appendFile(data, options)`