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#49298
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
deokjinkim authored and alexfernandez committed Nov 1, 2023
1 parent c72fcfd commit fc0ee01
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 @@ -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 fc0ee01

Please sign in to comment.