gossamer/text_decoder
Types
Decodes a stream of bytes into text using a specified character encoding.
See TextDecoder on MDN.
pub type TextDecoder
pub type TextDecoderOption {
Fatal
IgnoreBom
}
Constructors
-
FatalWhen set, decoding invalid data returns an error instead of substituting malformed data with a replacement character.
-
IgnoreBomIndicates whether the byte order mark will be included in the output or skipped over. It defaults to false, which means that the byte order mark will be skipped over when decoding and will not be included in the decoded text.
Values
pub fn decode(input: array_buffer.ArrayBuffer) -> String
Turns binary data, often in the form of a Uint8Array, into a string given the encoding.
pub fn decode_chunk(
decoder: TextDecoder,
input: array_buffer.ArrayBuffer,
) -> Result(String, js_error.JsError)
Decodes a chunk of bytes, keeping state for multi-byte sequences that
span chunks. Returns an error if the decoder was created with Fatal
and the input contains malformed data.
pub fn decode_with(
input: array_buffer.ArrayBuffer,
label: String,
with options: List(TextDecoderOption),
) -> Result(String, js_error.JsError)
Turns binary data into a string using the given encoding and options.
Returns an error if label isn’t a recognized encoding, or if the
options include Fatal and decoding encounters malformed data.
pub fn encoding(of decoder: TextDecoder) -> encoding.Encoding
pub fn flush(
decoder: TextDecoder,
) -> Result(String, js_error.JsError)
Emits any remaining bytes buffered from prior decode_chunk calls.
Returns an error if the decoder was created with Fatal and an
incomplete multi-byte sequence was left in the buffer.
pub fn is_fatal(decoder: TextDecoder) -> Bool
pub fn is_ignore_bom(decoder: TextDecoder) -> Bool
pub fn new() -> TextDecoder
pub fn new_with(
label: String,
with options: List(TextDecoderOption),
) -> Result(TextDecoder, js_error.JsError)
Creates a TextDecoder with the given encoding label and options.
Returns an error if the label isn’t a recognized encoding.