Functions
decode
fn (s: Str): Bytes
Decode s base64 string to a byte array.
Example
encoded "SGVsbG8="
bytes decode(encoded)
// bytes = [72, 101, 108, 108, 111]
decode-url
fn (s: Str): Bytes
Decode URL-safe base64 string (with or without padding) to bytes.
Example
decode-url("SGVsbG8")
// [72, 101, 108, 108, 111]
encode
fn (data: Bytes): Str
Encode data byte array to a base64 string.
Example
data [72, 101, 108, 108, 111] // "Hello" as bytes
result encode(data)
// result = "SGVsbG8="
encode-url
fn (data: Str | Bytes): Str
Encode data to URL-safe base64 string (no padding).
Uses - and _ instead of + and /. Safe for URLs and filenames.
Example
encode-url("Hello+World/Test")
// "SGVsbG8rV29ybGQvVGVzdA" (no = padding, - and _ chars)
is-valid
fn (s: Str): Bool
Check if string s is valid base64.
Example
is-valid("SGVsbG8=") // true
is-valid("not valid!") // false