gossamer/stream/transform_stream
The transform side of the Streams API — a writable + readable pair
where each chunk written passes through a transformer to produce
output. Pipe one through readable_stream.pipe_through to
connect transformations.
Types
The configuration for a TransformStream.
pub opaque type Builder(input, output)
A JavaScript TransformStream — a writable side that receives
input and a readable side that produces transformed output.
See TransformStream on MDN.
pub type TransformStream(input, output)
Values
pub fn build(
builder: Builder(input, output),
) -> Result(
TransformStream(input, output),
stream.StreamLifecycleError,
)
Creates a TransformStream from the configured Builder. Returns
Errored if the start callback throws synchronously; the thrown
value is the variant’s reason.
pub fn from_transform(
transform: fn(
input,
default_controller.DefaultController(output),
) -> b,
) -> TransformStream(input, output)
Creates a TransformStream from only a transform callback — use
when the transformer just maps input chunks to output chunks. If
the callback returns a Promise, the stream waits for it before
accepting the next chunk.
pub fn read_write_pair(
stream: TransformStream(input, output),
) -> #(
readable_stream.ReadableStream(output),
writable_stream.WritableStream(input),
)
Returns the readable and writable sides of the stream as a tuple.
Convenient for passing directly to
readable_stream.pipe_through.
pub fn readable(
stream: TransformStream(input, output),
) -> readable_stream.ReadableStream(output)
The readable side of the stream, producing the transformed output chunks.
pub fn with_cancel(
builder: Builder(input, output),
cancel: fn(dynamic.Dynamic) -> b,
) -> Builder(input, output)
Registers the cancel callback that runs when either side is
aborted. Receives the cancellation reason. If the callback returns
a Promise, the stream waits for it before resolving the cancel.
pub fn with_flush(
builder: Builder(input, output),
flush: fn(default_controller.DefaultController(output)) -> b,
) -> Builder(input, output)
Registers the flush callback that runs once after the writable
side closes. Use to emit any buffered output. If the callback
returns a Promise, the stream waits for it before resolving the
close.
pub fn with_readable_strategy(
builder: Builder(input, output),
strategy: stream.QueuingStrategy,
) -> Builder(input, output)
Sets the queuing strategy for the readable side of the transform.
Without this, the readable side uses the default strategy
(chunk count, high water mark of 0 — which buffers nothing
downstream until the consumer pulls).
pub fn with_start(
builder: Builder(input, output),
start: fn(default_controller.DefaultController(output)) -> b,
) -> Builder(input, output)
Registers the start callback that runs once at construction. Use
to enqueue initial chunks or set up state. If the callback returns
a Promise, the stream waits for it before any transforms run.
pub fn with_transform(
builder: Builder(input, output),
transform: fn(
input,
default_controller.DefaultController(output),
) -> b,
) -> Builder(input, output)
Registers the transform callback that runs for each input chunk.
Use to map input chunks to output chunks. If the callback returns a
Promise, the stream waits for it before accepting the next chunk.
pub fn with_writable_strategy(
builder: Builder(input, output),
strategy: stream.QueuingStrategy,
) -> Builder(input, output)
Sets the queuing strategy for the writable side of the transform.
Without this, the writable side uses the default strategy
(chunk count, high water mark of 1).
pub fn writable(
stream: TransformStream(input, output),
) -> writable_stream.WritableStream(input)
The writable side of the stream, accepting the input chunks.