summaryrefslogtreecommitdiff
path: root/lib/fs.js
diff options
context:
space:
mode:
authorLivia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com>2022-02-27 20:56:09 +0800
committerGitHub <noreply@github.com>2022-02-27 12:56:09 +0000
commit80bfb9b21a7d0f730c63e03ca6908ae25c48a18d (patch)
treeec3bd4d5cf2ace077838fc36c7a0f5f419c000b6 /lib/fs.js
parent135fa650103a69768c30cc2dbb5a7109d6afda8f (diff)
downloadnode-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.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/fs.js b/lib/fs.js
index b8a5cefa1b..611eaaa90c 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -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) {