Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: allow no-params fsPromises fileHandle read #38287

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
  • Loading branch information
Linkgoron authored and aduh95 committed Apr 21, 2021
commit 5370220ab2e8978611a827ac11aba1318bb93969
2 changes: 1 addition & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 8 additions & 0 deletions test/parallel/test-fs-promises-file-handle-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ async function validateLargeRead(options) {
assert.strictEqual(readHandle.bytesRead, 0);
}

async function validateReadNoParams() {
const filePath = fixtures.path('x.txt');
const fileHandle = await open(filePath, 'r');
// Should not throw
await fileHandle.read();
}


(async function() {
tmpdir.refresh();
Expand All @@ -70,4 +77,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());