- From: Mattias Buelens <notifications@github.com>
- Date: Thu, 07 Aug 2025 23:22:06 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 8 August 2025 06:22:10 UTC
MattiasBuelens left a comment (whatwg/streams#1348)
Fair point. We will probably need an opt-in on the underlying sink, similar to how you need to specify `type: "bytes"` to allow BYOB reads in the first place.
```javascript
const readable = new ReadableStream({
  type: "bytes",
  shared: true, // name to be decided
  pull(controller) {
    const { byobRequest } = controller;
    // This must always throw
    byobRequest.view.buffer.transfer();
  }
})
```
I think this is doable?
* A `SharedArrayBuffer` is non-transferable, so it will already throw on `transfer()`.
* A regular `ArrayBuffer` is transferable, so we have to create a non-transferable version to give to the BYOB request. We could use [`DetachArrayBuffer`](https://tc39.es/ecma262/#sec-detacharraybuffer) and pass a custom detach key, so it can only be transferred by the `ReadableStream` implementation. This is similar to how a non-shared `WebAssembly.Memory` works.
Maybe I should just start writing a spec for this... 😅
-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1348#issuecomment-3166709145
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/streams/issues/1348/3166709145@github.com>
Received on Friday, 8 August 2025 06:22:10 UTC