Skip to content

Convenience method to stream a response as text #1861

@foolip

Description

@foolip

What problem are you trying to solve?

response.body is a stream of Uint8Array but often you want to deal with text. response.text() decodes the response body as text and returns it, but all at once, not streaming.

What solutions exist today?

let response = await fetch('/');
let decoder = new TextDecoderStream();
response.body.pipeThrough(decoder);

How would you solve it?

A textStream() helper that gives you a stream of decoded text chunks instead.

Anything else?

This is mainly motivated by whatwg/html#11669, where a ReadableStream will needed. If it's as easy to get a string stream as a byte stream, then we could probably make those APIs only accept strings. (My current thinking was to bake text decoding into them to reduce boilerplate, but @noamr suggested a new method instead.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions