Skip to content

bytes

The bytes Library is part of the Standard Library, so every Group holds it. A Script imports the names it uses, as in use toHex from bytes. Its normative source is spec/stdlib/bytes.talk, and the full rules are in chapter 7.

An argument of the wrong kind raises wrong kind before any work is done, so the entries below list only the other errors each raises (every stdlib function).

toHex(b)

The Bytes b as lowercase hexadecimal text, two digits per byte.

fromHex(t)

The Bytes the hexadecimal text t writes.

Also raises: can't convert.

toBase64(b)

The Bytes b in the base64 alphabet of RFC 4648, padded.

fromBase64(t)

The Bytes the padded base64 text t writes.

Also raises: can't convert.

toBase64Url(b)

The Bytes b in the base64url alphabet of RFC 4648, unpadded.

fromBase64Url(t)

The Bytes the unpadded base64url text t writes.

Also raises: can't convert.

decodeText(b, encoding = "utf-8", mode = "strict")

The text the Bytes b hold in encoding, normalised to NFC.

Also raises: can't convert, out of domain.

encodeText(t, encoding = "utf-8")

The Bytes of the text t in encoding.

Also raises: can't convert, out of domain.

The encodings decodeText and encodeText name. The full rules: chapter 7.

  • "utf-8": UTF-8, as the Unicode Standard defines it; a leading U+FEFF is dropped when decoding.
  • "utf-16le": UTF-16, each code unit little-endian, with surrogate pairs; a leading U+FEFF is dropped when decoding.
  • "utf-16be": UTF-16, each code unit big-endian, with surrogate pairs; a leading U+FEFF is dropped when decoding.
  • "latin-1": ISO/IEC 8859-1: each byte is the code point of the same value, from U+0000 to U+00FF.
  • "windows-1252": The windows-1252 index of the WHATWG Encoding Standard: bytes 0x80 to 0x9F map as that index says, and every other byte as in latin-1.