diff options
author | Livia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com> | 2022-02-27 20:56:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-27 12:56:09 +0000 |
commit | 80bfb9b21a7d0f730c63e03ca6908ae25c48a18d (patch) | |
tree | ec3bd4d5cf2ace077838fc36c7a0f5f419c000b6 /lib/fs.js | |
parent | 135fa650103a69768c30cc2dbb5a7109d6afda8f (diff) | |
download | node-new-80bfb9b21a7d0f730c63e03ca6908ae25c48a18d.tar.gz |
fs: adjust default `length` for `fs.readSync` and fsPromises/`read`
Makes default length reasonable when nonzero offset is set.
PR-URL: https://github.com/nodejs/node/pull/42128
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -604,7 +604,7 @@ function read(fd, buffer, offset, length, position, callback) { if (arguments.length <= 3) { // Assume fs.read(fd, options, callback) - let options = {}; + let options = ObjectCreate(null); if (arguments.length < 3) { // This is fs.read(fd, callback) // buffer will be the callback @@ -621,7 +621,7 @@ function read(fd, buffer, offset, length, position, callback) { buffer = Buffer.alloc(16384), offset = 0, length = buffer.byteLength - offset, - position + position = null } = options); } @@ -686,10 +686,14 @@ function readSync(fd, buffer, offset, length, position) { validateBuffer(buffer); if (arguments.length <= 3) { - // Assume fs.read(fd, buffer, options) - const options = offset || {}; + // Assume fs.readSync(fd, buffer, options) + const options = offset || ObjectCreate(null); - ({ offset = 0, length = buffer.byteLength, position } = options); + ({ + offset = 0, + length = buffer.byteLength - offset, + position = null + } = options); } if (offset == null) { |