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 Aug 25, 2023
1 parent 33710e7 commit c5cad08
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,8 @@ class FileHandle extends EventEmitter {
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 @@ -319,14 +310,16 @@ class FileHandle extends EventEmitter {
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 c5cad08

Please sign in to comment.