Skip to content

Commit

Permalink
fs: allow no-params fsPromises fileHandle read
Browse files Browse the repository at this point in the history
allow no-params read for fsPromises fileHandle read
  • Loading branch information
Linkgoron committed Apr 18, 2021
1 parent bc31dc0 commit 16e4d5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/api/fs.md
Expand Up @@ -285,7 +285,7 @@ Reads data from the file and stores that in the given buffer.
If the file is not modified concurrently, the end-of-file is reached when the
number of bytes read is zero.
#### `filehandle.read(options)`
#### `filehandle.read([options])`
<!-- YAML
added:
- v13.11.0
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/fs/promises.js
Expand Up @@ -400,6 +400,9 @@ async function open(path, flags, mode) {
async function read(handle, bufferOrOptions, offset, length, position) {
let buffer = bufferOrOptions;
if (!isArrayBufferView(buffer)) {
if (bufferOrOptions === undefined) {
bufferOrOptions = {};
}
if (bufferOrOptions.buffer) {
buffer = bufferOrOptions.buffer;
validateBuffer(buffer);
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-fs-promises-file-handle-read.js
Expand Up @@ -61,6 +61,12 @@ async function validateLargeRead(options) {
assert.strictEqual(readHandle.bytesRead, 0);
}

async function validateReadNoParams() {
const filePath = fixtures.path('x.txt');
const fileHandle = await open(filePath, 'r');
assert.doesNotReject(fileHandle.read());
}


(async function() {
tmpdir.refresh();
Expand All @@ -70,4 +76,5 @@ async function validateLargeRead(options) {
await validateRead('', 'read-empty-file-conf', { useConf: true });
await validateLargeRead({ useConf: false });
await validateLargeRead({ useConf: true });
await validateReadNoParams();
})().then(common.mustCall());

0 comments on commit 16e4d5a

Please sign in to comment.