-
Notifications
You must be signed in to change notification settings - Fork 395
Add a textStream() method to the Body mixin #1862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8259,6 +8259,7 @@ interface mixin Body { | |
| [NewObject] Promise<FormData> formData(); | ||
| [NewObject] Promise<any> json(); | ||
| [NewObject] Promise<USVString> text(); | ||
| [NewObject] ReadableStream textStream(); | ||
| };</pre> | ||
|
|
||
| <p class=note>Formats you would not want a network layer to be dependent upon, such as | ||
|
|
@@ -8300,6 +8301,9 @@ due course. | |
|
|
||
| <dt><code><var>requestOrResponse</var> . <a method for=Body>text</a>()</code> | ||
| <dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as string. | ||
|
|
||
| <dt><code><var>requestOrResponse</var> . <a method for=Body>textStream</a>()</code> | ||
| <dd><p>Returns a {{ReadableStream}} with <var>requestOrResponse</var>'s body as string chunks. | ||
| </dl> | ||
|
|
||
| <hr> | ||
|
|
@@ -8473,6 +8477,43 @@ of running <a for=Body>consume body</a> with <a>this</a> and <a>parse JSON from | |
| of running <a for=Body>consume body</a> with <a>this</a> and <a>UTF-8 decode</a>. | ||
| </div> | ||
|
|
||
| <div algorithm> | ||
| <p>The <dfn method for=Body><code>textStream()</code></dfn> method steps are:</p> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for the null case it'd be nicer to return an empty stream, similar to what Another thing that's not entirely clear to me is whether piping ends up making the underlying stream unusable so that you can't invoke
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I didn't realize what I thought this should behave like when you try to use both Since it's not possible to call
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not be possible.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good, that should be easy to achieve, even though the current spec text doesn't make clear what happens.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| <ol> | ||
| <li><p>If <span>this</span> is <a for=Body>unusable</a>, then throw a {{TypeError}}. | ||
|
|
||
| <li> | ||
| <p>If <span>this</span>'s <a for=Body>body</a> is null: | ||
|
|
||
| <ol> | ||
| <li><p>Let <var>emptyStream</var> be a new {{ReadableStream}} in <a>this</a>'s | ||
| <a>relevant realm</a>. | ||
|
|
||
| <li><p><a for="ReadableStream">Set up</a> <var>emptyStream</var>. | ||
|
|
||
| <li><p><a for="ReadableStream">Close</a> <var>emptyStream</var>. | ||
|
|
||
| <li><p>Return <var>emptyStream</var>. | ||
| </ol> | ||
|
|
||
| <li><p>Let <var>stream</var> be <a>this</a>'s <a for=Body>body</a>'s <a for=body>stream</a>. | ||
|
|
||
| <li><p>Let <var>decoder</var> be a new {{TextDecoderStream}} object in <a>this</a>'s | ||
| <a>relevant realm</a>. | ||
|
|
||
| <li> | ||
| <p><a data-lt="set up a text decoder stream">Set up</a> <var>decoder</var> with <a | ||
| for=/>UTF-8</a>. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no newline inside phrasing |
||
|
|
||
| <p class=note>This is done regardless of the presence or the value of a | ||
| `<code>Content-Type</code>` header and regardless of the presence or the value of a | ||
| `<code>charset</code>` parameter.</p> | ||
|
|
||
| <li><p>Return the result of <var>stream</var>, <a>piped through</a> <var>decoder</var>. | ||
| </ol> | ||
| </div> | ||
|
|
||
|
|
||
| <h3 id=request-class>Request class</h3> | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.