From 9048caee577393edb1a596b46bc1ad097269cfc4 Mon Sep 17 00:00:00 2001 From: Sk Sajidul Kadir Date: Tue, 17 Mar 2020 00:50:27 +1100 Subject: [PATCH 1/5] fs: Add fs.readv() --- 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.js | 97 +++++++++++++++++++++++++ 6 files changed, 318 insertions(+) create mode 100644 test/parallel/test-fs-readv-promises.js create mode 100644 test/parallel/test-fs-readv.js diff --git a/doc/api/fs.md b/doc/api/fs.md index 74c73e972086f6..1d4be5db170140 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3062,6 +3062,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])`