Standard library · Bytes
- The language
- Agents and tools
- Model providers
- The Anthropic API
- Talking agents
- Standard library
- Glossary
- Package docs
- Telemetry
- Robots
- Servers
- Deploying
- tin.ad
- The tin command
- How it works
On this page
Bytes
Binary data: raw bytes, with hex and base64 in both directions. text() checks that the bytes are UTF-8.
Example
let b = "Tin".bytes()
print(b.hex())
print(b.base64())
print(b.at(0))
print(base64Bytes("VGlu").unwrap().text().unwrap()) 54696e
VGlu
84
Tin All 14 symbols
Bytesstring.bytesbytesOfBytes.atBytes.sliceBytes.concatBytes.findBytes.toArrayBytes.textBytes.showBytes.hexhexBytesBytes.base64base64Bytes
Bytes
type Bytes = { } No summary yet; the signature is the whole description.
string.bytes
fn string.bytes(s: string): Bytes The UTF-8 bytes of a string.
bytesOf
fn bytesOf(xs: int[]): Bytes Bytes from numbers 0..255; anything else panics.
Bytes.at
fn Bytes.at(b: Bytes, i: int): int The byte at i, 0..255.
Bytes.slice
fn Bytes.slice(b: Bytes, from: int, to: int): Bytes The bytes from \`from\` up to \`to\` (clamped).
Bytes.concat
fn Bytes.concat(a: Bytes, b: Bytes): Bytes These bytes followed by those.
Bytes.find
fn Bytes.find(b: Bytes, byte: int, from: int): int Where \`byte\` first appears at or after \`from\`, or -1.
Bytes.toArray
fn Bytes.toArray(b: Bytes): int[] The bytes as numbers 0..255.
Bytes.text
fn Bytes.text(b: Bytes): Result<string, string> The bytes as text, if they are valid UTF-8.
Bytes.show
fn Bytes.show(b: Bytes): string No summary yet; the signature is the whole description.
Bytes.hex
fn Bytes.hex(b: Bytes): string Lower-case hex, two digits a byte.
hexBytes
fn hexBytes(s: string): Result<Bytes, string> Bytes from hex text (either case, no separators).
Bytes.base64
fn Bytes.base64(b: Bytes): string Standard base64 (RFC 4648, with = padding).
base64Bytes
fn base64Bytes(s: string): Result<Bytes, string> Bytes from base64 text: standard or URL-safe alphabet, padding optional, no whitespace.