Re: [whatwg/fetch] Convenience method to stream a response as text (Issue #1861)

bakkot left a comment (whatwg/fetch#1861)

Sounds good to me, this is a pretty common use case in my experience, maybe getting more so with chatbots and similar streaming their responses. An additional reason not yet mentioned is that people who are unaware of `TextDecoderStream` may be tempted to do decoding one chunk at a time without a stateful `TextDecoder`, which will break if the end of a chunk happens to fall within a multi-byte character.

I agree it's unlikely we'll want a streaming version of `.json`. I could theoretically see value in a streaming `.formData` for the service worker use case - page submits a form with a file, service worker wants to modify some field but doesn't want to have to block on reading the whole file into memory. But that would require a bunch of other infrastructure and in any case is not ruled out by adding `textStream` if that use case becomes important someday.

I note that `TextDecoder` and `TextDecoderStream` support many more encodings than utf-8. I would think this should as well, given that the platform already supports those, but @annevk has [objected](https://github.com/whatwg/streams/issues/1019#issuecomment-2017396497) to adding support in a similar API on the grounds that you should just fix legacy content. (In my experience web developers are very rarely in a position to fix legacy content.)

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1861#issuecomment-3361323955
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1861/3361323955@github.com>

Received on Thursday, 2 October 2025 13:53:35 UTC