tyoshino / fetch-with-streams

Fetch API integrated with Streams.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fetch API integrated with Streams

This document is about the integration of the Streams API with the Fetch API. Basically, the integration only adds a way to represent the body data and does not affect the fetch algorithm.

[Bodies] (https://fetch.spec.whatwg.org/#bodies)

A body is a byte stream, which means it is a piped pair of readable and writable byte streams. It has an associated ...(the original description follows)

The read end of a body is the readable stream of the body. It is of type ReadableByteStream.

The write end of a body is the writable stream of the body. It is of type WritableStream.

Body mixin

callback BodyStreamInit = void (WritableStream);
typedef (Blob or BufferSource or FormData or URLSearchParams or USVString or BodyStreamInit) BodyInit;

To extract a byte stream and a 'Content-Type' value from a BodyStreamInit object, run these steps:

  1. Let stream be an empty byte stream.
  2. Let Content-Type be null.
  3. Call object with the write end of the body. Rethrow any exception.
  4. Return stream and Content-Type.
[NoInterfaceObject] interface Body {
    readonly attribute ReadableByteStream body;
    ...
};

Objects implementing the Body mixin gain an associated body (a pair of readable and writable byte streams) and a MIME type (initially the empty byte sequence). Objects implments the Body mixin expose methods and attributes of the read end of the body. The bodyUsed attribute's getter must return if the read end of the body is locked. The body attribute's getter must return the read end of the body.

Objects implementing the Body mixin also have an associated consume body algorithm, which given a type, runs these steps:

  1. Let p be a new promise.
  2. Let stream be the read end of the body.
  3. If stream is locked, reject p with a TypeError.
  4. Otherwise, acquire an exclusive lock of stream and run these substeps in parallel: (the original algorithm follows...)

About

Fetch API integrated with Streams.