Skip to content

Commit c5cad08

Browse files
authored
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 33710e7 commit c5cad08

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
@@ -282,17 +282,8 @@ class FileHandle extends EventEmitter {
282282
this[kHandle],
283283
undefined,
284284
{ ondone: () => this[kUnref]() });
285-
286-
const {
287-
readableStreamCancel,
288-
} = require('internal/webstreams/readablestream');
289-
this[kRef]();
290-
this.once('close', () => {
291-
readableStreamCancel(readable);
292-
});
293285
} else {
294286
const {
295-
readableStreamCancel,
296287
ReadableStream,
297288
} = require('internal/webstreams/readablestream');
298289

@@ -319,14 +310,16 @@ class FileHandle extends EventEmitter {
319310
ondone();
320311
},
321312
});
322-
323-
this[kRef]();
324-
325-
this.once('close', () => {
326-
readableStreamCancel(readable);
327-
});
328313
}
329314

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

0 commit comments

Comments
 (0)