Wren

Module encoding

TextEncoder and TextDecoder (Encoding Standard). Decoders keep their state between calls, so every WHATWG label works, in replacement or fatal mode, with BOM handling and stream: a sequence cut between two chunks is completed by the next call. Output is UTF-8.

Exposed to: Window, Worker. Source: api/encoding.widl.

Odin: import "wren:encoding".

Types

handle TextDecoder : Object

Checked by the browser on every call (lookup_TextDecoder).

flags TextDecoderOptions : u32

TextDecoderOptions

memberbit
Fatal0
Ignore_BOM1

struct EncodeIntoResult

What TextEncoder.encodeInto did, in bytes.

fieldtype
readu64Bytes of the source consumed (whole characters only).
writtenu64Bytes written to the destination.

Functions

TextEncoder_encode

Buffer TextEncoder_encode(usvstring text) raises

new TextEncoder().encode(text): a buffer of UTF-8. Quota past the page's memory limit.

Raises: returns an Error (see web).

Host: TextEncoder_encode :: proc(c: ^Call, text: string) -> (u64, Api_Error)

TextEncoder_encodeInto

EncodeIntoResult TextEncoder_encodeInto(bytes source, out bytes destination)

encoder.encodeInto(source, destination): invalid UTF-8 in the source counts as U+FFFD (3 bytes).

Host: TextEncoder_encodeInto :: proc(c: ^Call, source: []u8, destination: []u8) -> Api_EncodeIntoResult

TextDecoder_create

TextDecoder TextDecoder_create(string label = "", TextDecoderOptions options = none) raises

new TextDecoder(label, options): Range for an unknown label ("" = utf-8).

Raises: returns an Error (see web).

Host: TextDecoder_create :: proc(c: ^Call, label: string, options: Api_TextDecoderOptions) -> (u64, Api_Error)

TextDecoder_encoding

string TextDecoder_encoding(TextDecoder decoder)

decoder.encoding (lower case)

Host: TextDecoder_encoding :: proc(c: ^Call, decoder: Api_TextDecoder) -> string

TextDecoder_flags

TextDecoderOptions TextDecoder_flags(TextDecoder decoder)

decoder.fatal and decoder.ignoreBOM

Host: TextDecoder_flags :: proc(c: ^Call, decoder: Api_TextDecoder) -> Api_TextDecoderOptions

TextDecoder_decode

string TextDecoder_decode(TextDecoder decoder, bytes input, bool stream = false) raises

decoder.decode(input, {stream}): Type for invalid input in fatal mode. TextDecoder_output reads the whole result again when the buffer was too small.

Raises: returns an Error (see web).

Has effects: call it once per result (no length query).

Host: TextDecoder_decode :: proc(c: ^Call, decoder: Api_TextDecoder, input: []u8, stream: bool) -> (string, Api_Error)

TextDecoder_decodeBuffer

string TextDecoder_decodeBuffer(TextDecoder decoder, Buffer input, bool stream = false) raises

The same from a buffer (a fetch body, a stream chunk).

Raises: returns an Error (see web).

Has effects: call it once per result (no length query).

Host: TextDecoder_decodeBuffer :: proc(c: ^Call, decoder: Api_TextDecoder, input: Api_Buffer, stream: bool) -> (string, Api_Error)

TextDecoder_output

string TextDecoder_output(TextDecoder decoder)

The result of the last decode.

Host: TextDecoder_output :: proc(c: ^Call, decoder: Api_TextDecoder) -> string

Edit this page on GitHub