[whatwg/streams] Keep partial bytes in the queue when closing a byte stream (PR #1389)

When a readable byte stream is closed while the first pending pull-into descriptor holds only part of an element, `ReadableByteStreamControllerClose` used to error the stream and throw. Its callers in "close a ReadableStream" and `ReadableByteStreamTee` use `!`, so that throw was not allowed.
 
Instead, the stream now becomes close-requested. When the underlying byte source responds to the pending BYOB request, the incomplete element is put back into the queue, and the pending read-into requests are handled as if they were made after `close()`: each one is fulfilled with as many whole elements as are available, or fails with a `TypeError` if not even one element is available. The stream becomes closed once the queue is drained. Similarly, a `read(view)` on a close-requested stream whose queue cannot reach the minimum fill no longer errors the stream.
 
Fixes #1387. Alternative to #1388.

- [ ] At least two implementers are interested (and none opposed):
   * …
   * …
- [x] [Tests](https://github.com/web-platform-tests/wpt) are written and can be reviewed and commented upon at:
   * https://github.com/web-platform-tests/wpt/pull/64155
- [ ] [Implementation bugs](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) are filed:
   * Chromium: …
   * Gecko: …
   * WebKit: …
   * Deno: …
   * Node.js: …
- [ ] [MDN issue](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) is filed: …
- [x] The top of this comment includes a [clear commit message](https://github.com/whatwg/meta/blob/main/COMMITTING.md) to use. <!-- If you created this PR from a single commit, Github copied its message. Otherwise, you need to add a commit message yourself. -->

(See [WHATWG Working Mode: Changes](https://whatwg.org/working-mode#changes) for more details.)

You can view, comment on, or merge this pull request online at:

  https://github.com/whatwg/streams/pull/1389

-- Commit Summary --

  * Keep partial bytes in the queue when closing a byte stream
  * Reuse existing abstract ops for close-requested byte streams
  * Clarify note in ReadableByteStreamControllerCommitPullIntoDescriptor

-- File Changes --

    M index.bs (127)
    M reference-implementation/lib/abstract-ops/readable-streams.js (107)

-- Patch Links --

https://github.com/whatwg/streams/pull/1389.patch
https://github.com/whatwg/streams/pull/1389.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1389
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/pull/1389@github.com>

Received on Saturday, 24 October 2026 18:19:51 UTC