Manuscript Documentation
v2026.12.0

@std/data/encoding.ms#

Import each required symbol with import Name from "@std/data/encoding.ms".

Base32Options Type#

Alphabet and padding for base32_encode and base32_decode.

Manuscript
type Base32Options {
    hex_alphabet Bool = false
    padded Bool = true
}

Base32Options.hex_alphabet#

True selects the extended hex alphabet 0-9/A-V.

Manuscript
hex_alphabet Bool = false

Base32Options.padded#

False omits (or forbids) the = padding.

Manuscript
padded Bool = true

ascii85_decode Function#

Decodes unframed ASCII85. ASCII bytes 0 through 32 are ignored, and z is valid only between groups. Rejects Adobe delimiters, one-digit tails, invalid characters and groups that overflow 32 bits. A negative max_bytes returns EINVAL; decoded output above it returns EOVERFLOW before the output is allocated.

Manuscript
fn ascii85_decode(text String, max_bytes Int? = null) Result[Bytes, Error] { ... }

ascii85_encode Function#

Encodes unframed ASCII85; complete groups of four zero bytes become z. No Adobe <~/~> delimiters are added. Example: ascii85_encode("hello".to_bytes()) is "BOu!rDZ".

Manuscript
fn ascii85_encode(data Bytes) String { ... }

ascii_decode Function#

Decodes 7-bit ASCII bytes. A byte above 0x7F returns EBADMSG.

Manuscript
fn ascii_decode(data Bytes) Result[String, Error] { ... }

ascii_encode Function#

Encodes text as 7-bit ASCII. A scalar above U+007F returns EBADMSG.

Manuscript
fn ascii_encode(text String) Result[Bytes, Error] { ... }

base32_decode Function#

Decodes uppercase RFC 4648 Base32, or 0-9/A-V when options.hex_alphabet is true. Padding must be exact and only at the end; padded: false forbids =. Whitespace and nonzero unused bits return EBADMSG. A negative max_bytes returns EINVAL; output exceeding it returns EOVERFLOW.

Manuscript
fn base32_decode(text String, options Base32Options = Base32Options(), max_bytes Int? = null) Result[Bytes, Error] { ... }

base32_encode Function#

Encodes uppercase RFC 4648 Base32, using the alphabet and padding in options. Example: base32_encode("f".to_bytes()) returns "MY======".

Manuscript
fn base32_encode(data Bytes, options Base32Options = Base32Options()) String { ... }

base64_decode Function#

Decodes standard Base64 by default; set url_safe: true for the URL-safe alphabet. padded: false expects text without = and rejects =. Whitespace and nonzero unused bits are always rejected. Malformed text returns EBADMSG; max_bytes behaves as in base32_decode.

Manuscript
fn base64_decode(text String, url_safe Bool = false, padded Bool = true, max_bytes Int? = null) Result[Bytes, Error] { ... }

base64_encode Function#

Encodes bytes as standard Base64 by default; set url_safe: true for URL-safe text and padded: false to omit =. Example: base64_encode("f".to_bytes(), padded: false) returns "Zg".

Manuscript
fn base64_encode(data Bytes, url_safe Bool = false, padded Bool = true) String { ... }

hex_decode Function#

Decodes hexadecimal text, upper or lower case. Odd length or a non-hex character returns EBADMSG. max_bytes bounds decoded output as in base32_decode.

Manuscript
fn hex_decode(text String, max_bytes Int? = null) Result[Bytes, Error] { ... }

hex_encode Function#

Encodes each byte as two lowercase hexadecimal digits.

Manuscript
fn hex_encode(data Bytes) String { ... }

latin1_decode Function#

Decodes ISO-8859-1 bytes, mapping every byte to the scalar of the same value.

Manuscript
fn latin1_decode(data Bytes) String { ... }

latin1_encode Function#

Encodes text as ISO-8859-1, one byte per scalar. A scalar above U+00FF returns EBADMSG.

Manuscript
fn latin1_encode(text String) Result[Bytes, Error] { ... }

utf16_decode Function#

Decodes UTF-16 bytes, little-endian unless little_endian is false. An odd length or an unpaired surrogate returns EBADMSG; a negative max_bytes returns EINVAL, and decoded text longer than max_bytes UTF-8 bytes returns EOVERFLOW.

Manuscript
fn utf16_decode(data Bytes, little_endian Bool = true, max_bytes Int? = null) Result[String, Error] { ... }

utf16_encode Function#

Encodes text as UTF-16 code units, little-endian unless little_endian is false. No byte order mark is written.

Manuscript
fn utf16_encode(text String, little_endian Bool = true) Bytes { ... }