Skip to content

Commit 8a90f55

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 <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent bc6e719 commit 8a90f55

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
@@ -285,7 +285,7 @@ Reads data from the file and stores that in the given buffer.
285285
If the file is not modified concurrently, the end-of-file is reached when the
286286
number of bytes read is zero.
287287
288-
#### `filehandle.read(options)`
288+
#### `filehandle.read([options])`
289289
<!-- YAML
290290
added:
291291
- v13.11.0

lib/internal/fs/promises.js

+3
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ async function open(path, flags, mode) {
400400
async function read(handle, bufferOrOptions, offset, length, position) {
401401
let buffer = bufferOrOptions;
402402
if (!isArrayBufferView(buffer)) {
403+
if (bufferOrOptions === undefined) {
404+
bufferOrOptions = {};
405+
}
403406
if (bufferOrOptions.buffer) {
404407
buffer = bufferOrOptions.buffer;
405408
validateBuffer(buffer);

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

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

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

6572
(async function() {
6673
tmpdir.refresh();
@@ -70,4 +77,5 @@ async function validateLargeRead(options) {
7077
await validateRead('', 'read-empty-file-conf', { useConf: true });
7178
await validateLargeRead({ useConf: false });
7279
await validateLargeRead({ useConf: true });
80+
await validateReadNoParams();
7381
})().then(common.mustCall());

0 commit comments

Comments
 (0)