From 6601fac06a3e6e69cdad22928e5173b600c15b3d Mon Sep 17 00:00:00 2001 From: Sk Sajidul Kadir Date: Tue, 17 Mar 2020 00:50:27 +1100 Subject: [PATCH] fs: add fs.readv() Fixes: https://github.com/nodejs/node/issues/2298 PR-URL: https://github.com/nodejs/node/pull/32356 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/fs.md | 56 ++++++++++++++ lib/fs.js | 35 +++++++++ lib/internal/fs/promises.js | 16 ++++ src/node_file.cc | 47 ++++++++++++ test/parallel/test-fs-readv-promises.js | 67 +++++++++++++++++ test/parallel/test-fs-readv-sync.js | 92 +++++++++++++++++++++++ test/parallel/test-fs-readv.js | 97 +++++++++++++++++++++++++ 7 files changed, 410 insertions(+) create mode 100644 test/parallel/test-fs-readv-promises.js create mode 100644 test/parallel/test-fs-readv-sync.js create mode 100644 test/parallel/test-fs-readv.js diff --git a/doc/api/fs.md b/doc/api/fs.md index 1d0d4cf7e83666..9cca6599b16525 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3080,6 +3080,42 @@ Returns the number of `bytesRead`. For detailed information, see the documentation of the asynchronous version of this API: [`fs.read()`][]. +## `fs.readv(fd, buffers[, position], callback)` + + +* `fd` {integer} +* `buffers` {ArrayBufferView[]} +* `position` {integer} +* `callback` {Function} + * `err` {Error} + * `bytesRead` {integer} + * `buffers` {ArrayBufferView[]} + +Read from a file specified by `fd` and write to an array of `ArrayBufferView`s +using `readv()`. + +`position` is the offset from the beginning of the file from where data +should be read. If `typeof position !== 'number'`, the data will be read +from the current position. + +The callback will be given three arguments: `err`, `bytesRead`, and +`buffers`. `bytesRead` is how many bytes were read from the file. + +## `fs.readvSync(fd, buffers[, position])` + + +* `fd` {integer} +* `buffers` {ArrayBufferView[]} +* `position` {integer} +* Returns: {number} The number of bytes read. + +For detailed information, see the documentation of the asynchronous version of +this API: [`fs.readv()`][]. + ## `fs.realpath(path[, options], callback)` + +* `buffers` {ArrayBufferView[]} +* `position` {integer} +* Returns: {Promise} + +Read from a file and write to an array of `ArrayBufferView`s + +The `Promise` is resolved with an object containing a `bytesRead` property +identifying the number of bytes read, and a `buffers` property containing +a reference to the `buffers` input. + +`position` is the offset from the beginning of the file where this data +should be read from. If `typeof position !== 'number'`, the data will be read +from the current position. + #### `filehandle.stat([options])`