From bebbed5414040f0b07fc8d728c9f6bda41ce270c Mon Sep 17 00:00:00 2001 From: wbt Date: Wed, 6 Oct 2021 11:30:36 -0400 Subject: [PATCH 1/2] lib: provide a more sensible default length Currently, specifying an `offset` without a `length` throws an ERR_OUT_OF_RANGE error. This provides a more sensible default. This change should only affect cases where no length is specified and a nonzero offset is, which are currently throwing errors. --- lib/fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index 7e126b84adec76..53b75adc7e1f2b 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -621,7 +621,7 @@ function read(fd, buffer, offset, length, position, callback) { ({ buffer = Buffer.alloc(16384), offset = 0, - length = buffer.byteLength, + length = buffer.byteLength - offset, position } = options); } From 2f24c18fad7005a7f6eea937d9f0f44e191a30dc Mon Sep 17 00:00:00 2001 From: wbt Date: Wed, 6 Oct 2021 11:30:39 -0400 Subject: [PATCH 2/2] doc: update read function docs to correspond Not 100% sure if this is all of them. --- doc/api/fs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index cea4f600ac8bd0..dadcd6371122e1 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -378,7 +378,7 @@ added: * `offset` {integer} The location in the buffer at which to start filling. **Default:** `0` * `length` {integer} The number of bytes to read. **Default:** - `buffer.byteLength` + `buffer.byteLength - offset` * `position` {integer} The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an integer, the current @@ -3022,7 +3022,7 @@ changes: * `options` {Object} * `buffer` {Buffer|TypedArray|DataView} **Default:** `Buffer.alloc(16384)` * `offset` {integer} **Default:** `0` - * `length` {integer} **Default:** `buffer.byteLength` + * `length` {integer} **Default:** `buffer.byteLength - offset` * `position` {integer|bigint} **Default:** `null` * `callback` {Function} * `err` {Error}