From d747a6f79af98a09e88a6330903e6e0023a1cb80 Mon Sep 17 00:00:00 2001 From: Ian Kerins Date: Sat, 19 Oct 2024 19:21:11 -0400 Subject: [PATCH] fs: make `FileHandle.readableWebStream` always create byte streams The original implementation of the experimental `FileHandle.readableWebStream` API created non-`type: 'bytes'` streams, which prevented callers from creating `mode: 'byob'` readers from the returned stream, which means they could not achieve the associated "zero-copy" performance characteristics. Then, #46933 added a parameter allowing callers to pass the `type` parameter down to the ReadableStream constructor, exposing the same semantics to callers of `FileHandle.readableWebStream`. But there is no point to giving callers this choice: FileHandle-derived streams are by their very nature byte streams. We should not require callers to explicitly opt in to having byte stream semantics. Moreover, I do not see a situation in which callers would ever want to have a non-bytes stream: bytes-streams only do anything differently than normal ones if `mode: 'byob'` is passed to `getReader`. So, remove the `options` parameter and always create a ReadableStream with `type: 'bytes'`. Fixes #54041. --- doc/api/fs.md | 12 ++-- lib/internal/fs/promises.js | 66 +++++++++---------- .../test-filehandle-readablestream.js | 63 +++--------------- 3 files changed, 46 insertions(+), 95 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index ab9977dfca70d4..04abb9654f015d 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -480,11 +480,14 @@ 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()`