gossamer/encoding/text_decoder_stream
A transform stream that decodes bytes into text in a specified
character encoding. Pipe a byte-producing ReadableStream through
the writable side and read decoded strings off the readable side.
Pair with
readable_stream.pipe_through
via read_write_pair.
Types
The configuration for a TextDecoderStream.
pub opaque type Builder
A stream-based decoder: writes bytes to the writable side, reads text from the readable side.
See TextDecoderStream on MDN.
pub type TextDecoderStream
Values
pub fn build(
builder: Builder,
) -> Result(TextDecoderStream, encoding.DecoderError)
Constructs a TextDecoderStream from the configured Builder.
Returns UnsupportedEncoding if the label isn’t an encoding the
runtime recognizes.
pub fn encoding(decoder: TextDecoderStream) -> String
The decoder’s resolved encoding name. A label like "sjis"
resolves to its canonical name "shift_jis".
pub fn is_fatal(decoder: TextDecoderStream) -> Bool
Whether decoding malformed data emits an error on the stream
instead of substituting it with a replacement character. Equivalent
to JavaScript’s decoder.fatal.
pub fn is_ignore_bom(decoder: TextDecoderStream) -> Bool
Whether the byte order mark is skipped over rather than included in
the decoded output. Equivalent to JavaScript’s decoder.ignoreBOM.
pub fn new(label: String) -> Builder
Creates a new Builder for the given encoding label. Both flags
default to False.
pub fn read_write_pair(
decoder: TextDecoderStream,
) -> #(
readable_stream.ReadableStream(String),
writable_stream.WritableStream(BitArray),
)
Returns the readable and writable sides of the decoder as a tuple.
Convenient for passing directly to
readable_stream.pipe_through.
pub fn readable(
decoder: TextDecoderStream,
) -> readable_stream.ReadableStream(String)
The readable side of the decoder, yielding decoded strings.
pub fn with_fatal(builder: Builder, fatal: Bool) -> Builder
Sets whether decoding malformed data emits an error on the stream instead of substituting it with a replacement character.
pub fn with_ignore_bom(
builder: Builder,
ignore_bom: Bool,
) -> Builder
Sets whether the byte order mark
is included in the decoded output (False) or skipped over (True).
pub fn writable(
decoder: TextDecoderStream,
) -> writable_stream.WritableStream(BitArray)
The writable side of the decoder, accepting input bytes.