Module: encoding.base64
Source: ./encoding/base64.reef
Overview
encoding/base64 - Base64 encoding and decoding (RFC 4648)
Provides functions to encode binary data to base64 strings and decode base64 strings back to binary data.
Supports both standard base64 and URL-safe base64 variants.
The decode functions (base64_decode, base64_decode_url, base64_decode_bytes) return core.result.Result, not a bare value: Ok on success (empty input "" is valid base64 and decodes to Ok("")), Err(core.error.Error) on wrong length or invalid character.
Usage: import encoding.base64 import core.result as result let encoded = base64_encode("Hello") // "SGVsbG8=" let decoded = result.unwrap_ok(base64_decode("SGVsbG8=")) // "Hello"
Functions
fn get_base64_alphabet(): string
Base64 alphabet (standard)
fn get_base64_alphabet_url(): string
Base64 alphabet (URL-safe)
fn base64_char(value: int, url_safe: bool): char
Get character for 6-bit value
fn base64_value(c: char, url_safe: bool): int
Get value for base64 character (-1 if invalid, -2 if padding)
fn base64_encode_internal(data: string, url_safe: bool): string
fn base64_decode_internal(encoded: string, url_safe: bool, status: [int]): string
Internal decode engine shared by base64_decode/base64_decode_url.
Decode logic is unchanged from the pre-Result implementation. Reports
success/failure via the status out-param (a 1-element array, following
the same ref-cell convention as encoding.json's count: [int]):
0 = success (including empty input, which decodes to "" and is valid)
1 = invalid length (not a multiple of 4)
2 = invalid character
The returned string is only meaningful when status[0] == 0.
fn base64_encode(data: string): string
Encodes data to standard base64
fn base64_decode(encoded: string): result.Result[string, error.Error]
Decodes standard base64 to data. Ok(decoded) on success — empty input "" is valid base64 and yields Ok(""). Err(InvalidInput) on wrong length or invalid character.
fn base64_encode_url(data: string): string
Encodes data to URL-safe base64
fn base64_decode_url(encoded: string): result.Result[string, error.Error]
Decodes URL-safe base64 to data. Ok(decoded) on success — empty input "" is valid base64 and yields Ok(""). Err(InvalidInput) on wrong length or invalid character.
fn base64_is_valid(encoded: string): bool
Validates a base64 string (strict mode, matching base64_decode_internal)
fn base64_encode_bytes(data: [int], len: int): string
Encodes byte array to base64
fn base64_decode_bytes(encoded: string, out: [int], max: int): result.Result[int, error.Error]
Decodes base64 into the caller-supplied byte array out (a deliberate
low-level out-param API — not modernized to a fresh array). The param
is named out rather than result to avoid colliding with the
core.result module alias used for this function's own return type.
Ok(byte count) on success — empty input "" is valid base64 and yields Ok(0). Err(InvalidInput) on wrong length or invalid character.
Generated by reefc doc