GizStack
View .mdOpen in ChatGPTOpen in Claude

gizlang/encoding

Web text encodings. Labels and error recovery follow the WHATWG Encoding Standard.

gizlang
import * as Encoding from "gizlang/encoding";

Functions

encoding

gizlang
function encoding(label: string): Option<string>

The canonical encoding of a supported label, or none.

Effects: fail, alloc.

bom

gizlang
function bom(data: bytes): Option<string>

The encoding named by a byte order mark, or none.

Effects: fail.

decode

gizlang
function decode(data: bytes, label: string = "utf-8", fatal: bool = false, ignoreBOM: bool = false): string throws string

Decode bytes of LABEL. Invalid sequences become U+FFFD, or throw with FATAL. A leading matching BOM is stripped unless IGNOREBOM is set, as TextDecoder specifies. An unsupported label throws.

Effects: fail, alloc.