gossamer/encoding/text_encoder_stream

A stream-based UTF-8 encoder. Wire writable(encoder) to a String source and readable(encoder) to a BitArray consumer to pipe text through encoding without buffering the whole input.

Types

A stream-based encoder: writes text to the writable side, reads UTF-8 bytes from the readable side.

See TextEncoderStream on MDN.

pub type TextEncoderStream

Values

pub fn new() -> TextEncoderStream

Creates a new TextEncoderStream that encodes text as UTF-8.

pub fn read_write_pair(
  encoder: TextEncoderStream,
) -> #(
  readable_stream.ReadableStream(BitArray),
  writable_stream.WritableStream(String),
)

Returns the readable and writable sides of the encoder as a tuple. Convenient for passing directly to readable_stream.pipe_through.

pub fn readable(
  encoder: TextEncoderStream,
) -> readable_stream.ReadableStream(BitArray)

The readable side of the stream — produces UTF-8 encoded bytes.

pub fn writable(
  encoder: TextEncoderStream,
) -> writable_stream.WritableStream(String)

The writable side of the stream — accepts text chunks to encode.

Search Document