diff --git a/fetch.bs b/fetch.bs index c17629dce..0b5972233 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1037,6 +1037,131 @@ worked on in issue #1156 body. +
To incrementally read a body body, given an +algorithm processBodyChunk, an algorithm processError, an optional null or +algorithm processEndOfBody (default +null), and an optional null or global object +taskDestination (default null), run these steps: + +
Assert: body's stream is non-null. + +
If taskDestination is null, then set taskDestination to the result of + starting a new parallel queue. + +
Let reader be the result of getting a reader for + body's stream. + +
This operation cannot throw an exception. + +
Perform the incrementally-read loop given reader, + taskDestination, processBodyChunk, processError, and + processEndOfBody. +
To perform the incrementally-read loop, given a {{ReadableStreamDefaultReader}} object +reader, parallel queue or global object taskDestination, +algorithm processBodyChunk, algorithm processError, and null or algorithm +processEndOfBody: + +
Let readRequest be the following read request: + +
Let continueAlgorithm be null. + +
If chunk is not a {{Uint8Array}} object, then set + continueAlgorithm to this step: run processError given a {{TypeError}}. + +
Otherwise: + +
Let bytes be a copy of + chunk. + +
Set continueAlgorithm to these steps: + +
Run processBodyChunk given bytes. + +
Perform the incrementally-read loop given reader, + taskDestination, processBodyChunk, processError, and + processEndOfBody. +
Queue a fetch task given continueAlgorithm and + taskDestination. +
If processEndOfBody is non-null, then queue a fetch task given + processEndOfBody and taskDestination.
Let errorAlgorithm be this step: run processError given + e. + +
Queue a fetch task given errorAlgorithm and + taskDestination. +
Read a chunk from reader given + readRequest. +
To fully read a body body, given an algorithm +processBody, an optional algorithm +processError, and an optional null or +global object taskDestination (default null), +run these steps: + +
If taskDestination is null, then set taskDestination to the result of + starting a new parallel queue. + +
Let promise be the result of fully reading body as promise given + body. + +
Let fulfilledSteps given a byte sequence bytes be to + queue a fetch task to run processBody given bytes, with + taskDestination. + +
Let rejectedSteps be to queue a fetch task to run processError, + with taskDestination. + +
React to promise with fulfilledSteps and + rejectedSteps. +
To fully read body as promise, given a +body body, run these steps: + +
Assert: body's stream is non-null. + +
Let reader be the result of getting a reader for + body's stream. If that threw an exception, then return + a promise rejected with that exception. + +
Return the result of reading all bytes from + reader. +
To handle content codings given codings and bytes, run these steps: @@ -5727,20 +5852,8 @@ the associated steps:
Let promise be a promise resolved with an empty byte sequence. -
If object's body is non-null, then: - -
Let reader be the result of getting a reader from - stream. If that threw an exception, then return a promise rejected with that - exception. - -
Set promise to the result of - reading all bytes from reader. -
If object's body is non-null, then set promise to the + result of fully reading body as promise given object's body.
Let steps be to return the result of package data with the first argument given, type, and object's MIME type.