std.base64
Base64 encoding and decoding.
import std.base64
Functions
encode
base64.encode(s: string) string
Encodes a string to standard base64.
let encoded = base64.encode("hello world")
// "aGVsbG8gd29ybGQ="
decode
base64.decode(s: string) string
Decodes a standard base64 string.
let decoded = base64.decode("aGVsbG8gd29ybGQ=")
// "hello world"
encode_bytes / decode_bytes
base64.encode_bytes(b: bytes) string
base64.decode_bytes(s: string) bytes
Standard base64 over a bytes buffer, exact for every byte value (the string forms are for text).
let enc = base64.encode_bytes("hi".to_bytes()) // "aGk="
let raw = base64.decode_bytes(enc) // 2 bytes
encode_url_safe
base64.encode_url_safe(s: string) string
Encodes a string to URL-safe base64 (uses - and _ instead of + and /).
decode_url_safe
base64.decode_url_safe(s: string) string
Decodes a URL-safe base64 string.
Example
import std.base64
fn main() {
let original = "hello world"
let encoded = base64.encode(original)
let decoded = base64.decode(encoded)
print(f"Encoded: {encoded}")
print(f"Decoded: {decoded}")
}