Re: [whatwg/fetch] Set body with byte reading support (PR #1593)

@annevk commented on this pull request.

I'll trust @domenic got the logic right. I have a few editorial comments and then it seems this can go in.

Will you file an MDN issue as well if needed?

> @@ -5961,25 +5961,68 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
    <li><p>Return the <a for=/>appropriate network error</a> for <var>fetchParams</var>.
   </ol>
 
- <li><p>Let <var>pullAlgorithm</var> be an algorithm that <a lt=resumed for=fetch>resumes</a> the
- ongoing fetch if it is <a lt=suspend for=fetch>suspended</a>.
+ <li>
+  <p>Let |buffer| be an empty buffer that can have bytes appended to it.
+
+  <p class="note">This represents an internal buffer inside the network layer of the user agent.
+
+ <li><p>Let |pullAlgorithm| be the followings steps:

If the `<li>` has multiple children, the `<p>` needs to be on its own line. (Applies several times.)

> +    <ol>
+     <li><p>If the size of |buffer| is smaller than a lower limit chosen by the user agent and the
+     ongoing fetch is [=fetch/suspend|suspended=], [=fetch/resumed|resume=] the fetch.
+
+     <li><p>Wait until |buffer| is not empty.
+
+     <li><p>[=Queue a fetch task=] to run the following steps, with |fetchParams|'s [=task destination=].
+
+      <ol>
+       <li><p>Let |available| be the size of |buffer|.
+
+       <li><p>Let |desiredSize| be |available|.
+
+       <li><p>If |stream|'s [=ReadableStream/current BYOB request view=] is non-null, then set
+       |desiredSize| to |stream|'s [=ReadableStream/current BYOB request view=]'s [=BufferSource/byte
+       length=].

No newlines inside terms.

> +       <li><p>Let <var>bytes</var> be the result of extracting |extractSize| of bytes from
+       <var>buffer</var>.
+
+       <li>If |stream|s [=ReadableStream/current BYOB request view=] is non-null, then
+       [=ArrayBufferView/write=] |bytes| into |stream|'s [=ReadableStream/current BYOB request
+       view=], and set |view| to |stream|'s [=ReadableStream/current BYOB request view=].
+
+       <li>Otherwise, set |view| to the result of [=ArrayBufferView/create|creating=] a
+       {{Uint8Array}} from |bytes| in |stream|'s [=relevant Realm=].
+
+       <li><p>[=ReadableStream/Enqueue=] |view| into |stream|.
+
+       <li><p>If |stream| is [=ReadableStream/errored=], then [=fetch controller/terminate=]
+       |fetchParams|'s [=fetch params/controller=].
+
+       <li><p>Resolve |promise| with undefined.

xref resolve

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/pull/1593#pullrequestreview-1299173288
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/pull/1593/review/1299173288@github.com>

Received on Wednesday, 15 February 2023 10:06:34 UTC