- From: Mattias Buelens <notifications@github.com>
- Date: Wed, 15 Jul 2026 03:01:19 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/1376/4979316320@github.com>
MattiasBuelens left a comment (whatwg/streams#1376)
> I know this has been discussed a number of times before but I would very much appreciate if we could revisit whether passing a sync iterable, string/single value to a `ReadableStream.from` would be possible.
Just for clarity: you *can* already pass any sync iterable (expect for strings) to `ReadableStream.from()`. That was always supported and remains supported, even after https://github.com/whatwg/streams/pull/1372.
So your question becomes: should `ReadableStream.from()` accept single chunks (that are not iterable) as well?
> The fundamental issue with this is that it's actually fairly difficult to optimize around since we are forced to allocate the `controller`, handle the `start` call and resulting microtask, etc.
For single chunks, I would think that requiring the chunk to be wrapped in an array makes the developer's intention more clear:
```javascript
ReadableStream.from([aSingleChunkOfSomething]);
ReadableStream.from([new Uint8Array(10)]);
```
Implementations could choose to optimize specifically for `ReadableStream.from(array)` and/or `ReadableStream.from(syncIterable)`. For example, you could invent your own (internal) controller that directly pulls chunks out of the array or iterable, if that turns out to be faster or more efficient than using a `ReadableStreamDefaultController` with an underlying source.
> Passing a string or BufferSource as a single value would special case in that they would not be treated as sync iterators:
>
> ```javascript
> ReadableStream.from('hello'); // yields only a single string 'hello' then closes
> ReadableStream.from(new Uint8Array(10)); // yields only the single Uint8Array
> ```
Typed arrays behave like regular arrays in a lot of ways, including sync iteration with `for..of`. So having `ReadableStream.from()` treat them specially seems really weird.
Strings are... awkward. I think it was a mistake to make them sync iterables, I would have preferred a separate `string.scalars()` method instead, like in Swift. But hindsight is 20/20. 😅
So we're left with the two options from https://github.com/whatwg/streams/pull/1310#issuecomment-2022484496: either we enqueue the individual code points (like `Iterator.from(string)`) or we enqueue the whole string (like `new Response(string).body`). I don't think *either* option would be intuitive, so disallowing strings altogether still seems like the safest option. Unless there are new arguments for or against one of these options?
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1376#issuecomment-4979316320
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/streams/issues/1376/4979316320@github.com>
Received on Wednesday, 15 July 2026 10:01:23 UTC