Skip to content

Commit

Permalink
fs: remove redundant code in readableWebStream()
Browse files Browse the repository at this point in the history
Remove redundant code by moving it to outside of `if/else`. Plus,
make `options` optional in doc.

PR-URL: nodejs/node#49298
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent b78535c commit bad1468
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion graal-nodejs/doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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.readableWebStream(options)`
#### `filehandle.readableWebStream([options])`
<!-- YAML
added: v17.0.0
Expand Down
23 changes: 8 additions & 15 deletions graal-nodejs/lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,8 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
this[kHandle],
undefined,
{ ondone: () => this[kUnref]() });

const {
readableStreamCancel,
} = require('internal/webstreams/readablestream');
this[kRef]();
this.once('close', () => {
readableStreamCancel(readable);
});
} else {
const {
readableStreamCancel,
ReadableStream,
} = require('internal/webstreams/readablestream');

Expand All @@ -313,14 +304,16 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
ondone();
},
});

this[kRef]();

this.once('close', () => {
readableStreamCancel(readable);
});
}

const {
readableStreamCancel,
} = require('internal/webstreams/readablestream');
this[kRef]();
this.once('close', () => {
readableStreamCancel(readable);
});

return readable;
}

Expand Down

0 comments on commit bad1468

Please sign in to comment.