TransformStream
A transform stream consists of a pair of streams: a writable stream, known as its writable side, and a readable stream, known as its readable side. Writes to the writable side result in new data being made available for reading from the readable side.
Workers currently only implements an identity transform stream, a type of transform stream which forwards all chunks written to its writable side to its readable side, without any changes.
-
TransformStream()
TransformStream- Returns a new identity transform stream.
readable
ReadableStream- An instance of a
ReadableStream
.
- An instance of a
writable
WritableStream- An instance of a
WritableStream
.
- An instance of a
The current implementation of TransformStream
in the Workers platform is not current compliant with the Streams Standard ↗ and we will soon be making changes to the implementation to make it conform with the specification. In preparation for doing so, we have introduced the IdentityTransformStream
class that implements behavior identical to the current TransformStream
class. This type of stream forwards all chunks of byte data (in the form of TypedArray
s) written to its writable side to its readable side, without any changes.
The IdentityTransformStream
readable side supports bring your own buffer (BYOB) reads ↗.
-
IdentityTransformStream()
IdentityTransformStream- Returns a new identity transform stream.
readable
ReadableStream- An instance of a
ReadableStream
.
- An instance of a
writable
WritableStream- An instance of a
WritableStream
.
- An instance of a
The FixedLengthStream
is a specialization of IdentityTransformStream
that limits the total number of bytes that the stream will passthrough. It is useful primarily because, when using FixedLengthStream
to produce either a Response
or Request
, the fixed length of the stream will be used as the Content-Length
header value as opposed to use chunked encoding when using any other type of stream. An error will occur if too many, or too few bytes are written through the stream.
-
FixedLengthStream(length)
FixedLengthStream- Returns a new identity transform stream.
length
maybe anumber
orbigint
with a maximum value of2^53 - 1
.
readable
ReadableStream- An instance of a
ReadableStream
.
- An instance of a
writable
WritableStream- An instance of a
WritableStream
.
- An instance of a