From 94f3eed22927cbd23de0bf077e567abf65b29338 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Thu, 16 Jan 2020 09:46:28 -0500 Subject: [PATCH] fs: make fs.read params optional This makes all the parameters of the `fs.read` function, except for `fd` and the callback(when not using as a promise) optional. They will default to sensible defaults. Fixes: https://github.com/nodejs/node/issues/31237 PR-URL: https://github.com/nodejs/node/pull/31402 Reviewed-By: Robert Nagy --- doc/api/fs.md | 34 ++++++++++++++++++ lib/fs.js | 26 ++++++++++++++ test/parallel/test-fs-read-optional-params.js | 36 +++++++++++++++++++ .../test-fs-read-promises-optional-params.js | 19 ++++++++++ 4 files changed, 115 insertions(+) create mode 100644 test/parallel/test-fs-read-optional-params.js create mode 100644 test/parallel/test-fs-read-promises-optional-params.js diff --git a/doc/api/fs.md b/doc/api/fs.md index c561715d1afbef..6cdd5bfdcb42c0 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2775,6 +2775,29 @@ The callback is given the three arguments, `(err, bytesRead, buffer)`. If this method is invoked as its [`util.promisify()`][]ed version, it returns a `Promise` for an `Object` with `bytesRead` and `buffer` properties. +## `fs.read(fd, [options,] callback)` + +* `fd` {integer} +* `options` {Object} + * `buffer` {Buffer|TypedArray|DataView} **Default:** `Buffer.alloc(16384)` + * `offset` {integer} **Default:** `0` + * `length` {integer} **Default:** `buffer.length` + * `position` {integer} **Default:** `null` +* `callback` {Function} + * `err` {Error} + * `bytesRead` {integer} + * `buffer` {Buffer} + +Similar to the above `fs.read` function, this version takes an optional `options` object. +If no `options` object is specified, it will default with the above values. + ## `fs.readdir(path[, options], callback)` +* `options` {Object} + * `buffer` {Buffer|Uint8Array} **Default:** `Buffer.alloc(16384)` + * `offset` {integer} **Default:** `0` + * `length` {integer} **Default:** `buffer.length` + * `position` {integer} **Default:** `null` +* Returns: {Promise} + #### `filehandle.readFile(options)`