Skip to content

Commit ef72490

Browse files
Linkgorontargos
authored andcommitted
fs: allow no-params fsPromises fileHandle read
allow no-params read for fsPromises fileHandle read PR-URL: #38287 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6350213 commit ef72490

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/api/fs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Reads data from the file and stores that in the given buffer.
275275
If the file is not modified concurrently, the end-of-file is reached when the
276276
number of bytes read is zero.
277277
278-
#### `filehandle.read(options)`
278+
#### `filehandle.read([options])`
279279
<!-- YAML
280280
added:
281281
- v13.11.0

lib/internal/fs/promises.js

+3
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ async function open(path, flags, mode) {
388388
async function read(handle, bufferOrOptions, offset, length, position) {
389389
let buffer = bufferOrOptions;
390390
if (!isArrayBufferView(buffer)) {
391+
if (bufferOrOptions === undefined) {
392+
bufferOrOptions = {};
393+
}
391394
if (bufferOrOptions.buffer) {
392395
buffer = bufferOrOptions.buffer;
393396
validateBuffer(buffer);

test/parallel/test-fs-promises-file-handle-read.js

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ async function validateLargeRead() {
6060
assert.strictEqual(readHandle.bytesRead, 0);
6161
}
6262

63+
async function validateReadNoParams() {
64+
const filePath = fixtures.path('x.txt');
65+
const fileHandle = await open(filePath, 'r');
66+
// Should not throw
67+
await fileHandle.read();
68+
}
69+
6370
let useConf = false;
6471

6572
(async function() {
@@ -72,4 +79,5 @@ let useConf = false;
7279
.then(validateLargeRead)
7380
.then(common.mustCall());
7481
}
82+
await validateReadNoParams();
7583
})().then(common.mustCall());

0 commit comments

Comments
 (0)