Re: [whatwg/streams] ReadableStream.prototype.text(), .blob(), and .bytes() (PR #1311)

@saschanaz commented on this pull request.



> @@ -534,6 +538,11 @@ dictionary StreamPipeOptions {
   boolean preventCancel = false;
   AbortSignal signal;
 };
+
+dictionary ConsumeBytesOptions {
+  AbortSignal signal;
+  USVString type = "";

1. This `type` is not super clear about what type it means, maybe `blobType`? Especially if we want to put more stream related options, because we already have `type` in `UnderlyingSource`.
2. Blob uses DOMString instead of USVString: https://w3c.github.io/FileAPI/#ref-for-dfn-BPtype
3. Should we have a separate dictionary without `type` for other non-blob methods?

> @@ -2661,6 +2688,99 @@ create them does not matter.
  1. Return « |branch1|, |branch2| ».
 </div>
 
+<div algorithm>
+To <dfn lt="fully read">fully read</dfn> a {{ReadableStream}} |stream|, given an algorithm |processBody|, and an algorithm |processBodyError|, run these steps. |processBody| must be an algorithm accepting a [=byte sequence=]. |processBodyError| must be an algorithm optionally accepting an exception.

Do we need this `lt`? Same for other `<dfn>`s.

> @@ -2661,6 +2688,99 @@ create them does not matter.
  1. Return « |branch1|, |branch2| ».
 </div>
 
+<div algorithm>
+To <dfn lt="fully read">fully read</dfn> a {{ReadableStream}} |stream|, given an algorithm |processBody|, and an algorithm |processBodyError|, run these steps. |processBody| must be an algorithm accepting a [=byte sequence=]. |processBodyError| must be an algorithm optionally accepting an exception.
+
+ 1. Let |successSteps| given a [=byte sequence=] |bytes| be to run |processBody| given |bytes|.
+ 1. Let |errorSteps| optionally given an exception |exception| be to run |processBodyError| given |exception|.
+ 1. Let |reader| be the result of getting a reader for |stream|. If that threw an exception, then run |errorSteps| with that exception and return.
+ 1. [=read all bytes|Read all bytes=] from |reader|, given |successSteps| and |errorSteps|.
+</div>
+
+<div algorithm>
+The <dfn lt="consume fully with abort">consume fully with abort</dfn> algorithm, given a {{ReadableStream}} |stream|, an optional {{AbortSignal}} |signal|, and an algorithm that takes a [=byte sequence=] and returns a JavaScript or throws an exception |convertBytesToJSValue|, runs these steps:

"consume fully" or "fully consume"? We already have "fully read", so maybe consistency?

And also "an algorithm |convertBytesToJSValue| that ..."

> @@ -2661,6 +2688,99 @@ create them does not matter.
  1. Return « |branch1|, |branch2| ».
 </div>
 
+<div algorithm>
+To <dfn lt="fully read">fully read</dfn> a {{ReadableStream}} |stream|, given an algorithm |processBody|, and an algorithm |processBodyError|, run these steps. |processBody| must be an algorithm accepting a [=byte sequence=]. |processBodyError| must be an algorithm optionally accepting an exception.
+
+ 1. Let |successSteps| given a [=byte sequence=] |bytes| be to run |processBody| given |bytes|.
+ 1. Let |errorSteps| optionally given an exception |exception| be to run |processBodyError| given |exception|.
+ 1. Let |reader| be the result of getting a reader for |stream|. If that threw an exception, then run |errorSteps| with that exception and return.
+ 1. [=read all bytes|Read all bytes=] from |reader|, given |successSteps| and |errorSteps|.
+</div>
+
+<div algorithm>
+The <dfn lt="consume fully with abort">consume fully with abort</dfn> algorithm, given a {{ReadableStream}} |stream|, an optional {{AbortSignal}} |signal|, and an algorithm that takes a [=byte sequence=] and returns a JavaScript or throws an exception |convertBytesToJSValue|, runs these steps:
+
+ 1. Let |promise| be [=a new promise=].
+ 1. Let |errorSteps| given |error| to be [=reject=] |promise| with |error|.
+ 1. Let |successSteps| given a [=byte sequence=] |data| be to [=resolve=] |promise| with the result of running |convertBytesToJSValue| with |data|. If that threw an exception, then run |errorSteps| with that exception.

Perhaps you want to name them as processBody and processBodyError as that's what the parameters of "fully read" are? Or maybe "fully read" parameters should be success/errorSteps instead.

> +
+<div algorithm>
+The <dfn lt="consume fully with abort">consume fully with abort</dfn> algorithm, given a {{ReadableStream}} |stream|, an optional {{AbortSignal}} |signal|, and an algorithm that takes a [=byte sequence=] and returns a JavaScript or throws an exception |convertBytesToJSValue|, runs these steps:
+
+ 1. Let |promise| be [=a new promise=].
+ 1. Let |errorSteps| given |error| to be [=reject=] |promise| with |error|.
+ 1. Let |successSteps| given a [=byte sequence=] |data| be to [=resolve=] |promise| with the result of running |convertBytesToJSValue| with |data|. If that threw an exception, then run |errorSteps| with that exception.
+ 1. If |signal| is not undefined,
+  1. Let |abortAlgorithm| be the following steps:
+   1. Let |error| be |signal|'s [=AbortSignal/abort reason=].
+   1. Run |errorSteps| with |error|.
+   1. Let |actions| be an empty [=ordered set=].
+   1. If |stream|.[=ReadableStream/[[state]]=] is "`readable`", [=set/append=] the following action action to |actions|:
+     1. return ! [$ReadableStreamCancel$](|stream|, |error|).
+     1. Otherwise, return [=a promise resolved with=] undefined.
+   1. [=Shutdown with an action=] consisting of [=getting a promise to wait for all=] of the actions

This is pipeTo specific, maybe we can simply call ReadableStreamCancel?

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

Message ID: <whatwg/streams/pull/1311/review/1994305033@github.com>

Received on Thursday, 11 April 2024 18:14:14 UTC