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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
deokjinkim authored and targos committed Nov 26, 2023
1 parent ddebd29 commit 69b7f91
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
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 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 69b7f91

Please sign in to comment.