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: #49298
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
deokjinkim authored and UlisesGascon committed Sep 10, 2023
1 parent ae65610 commit 92772a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion doc/api/fs.md
Expand Up @@ -446,7 +446,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 lib/internal/fs/promises.js
Expand Up @@ -281,17 +281,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 @@ -318,14 +309,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 92772a8

Please sign in to comment.