amber/web/text_decoder

Types

Represents a decoder for a specific text encoding, allowing you to convert binary data into a string given the encoding.

Examples

let decoder = text_decoder.new_with("utf-8", [])
let buffer = uint8_array.from_list([72, 101, 108, 108, 111])
let decoded_string =
  decoder |> text_decoder.decode_with(buffer |> uint8_array.buffer, [])
io.debug(decoded_string)
// => Outputs: "Hello"
pub type TextDecoder

Functions

pub fn decode(decoder: TextDecoder) -> String

Turns binary data, often in the form of a Uint8Array, into a string given the encoding.

pub fn decode_with(
  decoder: TextDecoder,
  input: ArrayBuffer,
  options: List(TextDecodeOption),
) -> String
pub fn new() -> TextDecoder
pub fn new_with(
  label: String,
  options: List(TextDecoderOption),
) -> TextDecoder
Search Document