Skip to content

Commit 92772a8

Browse files
deokjinkimUlisesGascon
authored andcommittedSep 10, 2023
fs: remove redundant code in readableWebStream()
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>

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed
 

‎doc/api/fs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ Reads data from the file and stores that in the given buffer.
446446
If the file is not modified concurrently, the end-of-file is reached when the
447447
number of bytes read is zero.
448448
449-
#### `filehandle.readableWebStream(options)`
449+
#### `filehandle.readableWebStream([options])`
450450
451451
<!-- YAML
452452
added: v17.0.0

‎lib/internal/fs/promises.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,8 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
281281
this[kHandle],
282282
undefined,
283283
{ ondone: () => this[kUnref]() });
284-
285-
const {
286-
readableStreamCancel,
287-
} = require('internal/webstreams/readablestream');
288-
this[kRef]();
289-
this.once('close', () => {
290-
readableStreamCancel(readable);
291-
});
292284
} else {
293285
const {
294-
readableStreamCancel,
295286
ReadableStream,
296287
} = require('internal/webstreams/readablestream');
297288

@@ -318,14 +309,16 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
318309
ondone();
319310
},
320311
});
321-
322-
this[kRef]();
323-
324-
this.once('close', () => {
325-
readableStreamCancel(readable);
326-
});
327312
}
328313

314+
const {
315+
readableStreamCancel,
316+
} = require('internal/webstreams/readablestream');
317+
this[kRef]();
318+
this.once('close', () => {
319+
readableStreamCancel(readable);
320+
});
321+
329322
return readable;
330323
}
331324

0 commit comments

Comments
 (0)
Please sign in to comment.