Base64 encoding / decoding for fastC.
Part of the fastc-core launch set. The implementation currently ships
inside the fastC compiler's built-in prelude — every fastC v1.0
program already gets use base64::* for free. This repository is the
public home for the module's API and will become installable via
fastc add github.com/Skelf-Research/fastc-core-base64 once stage 1.7's
vendor-consumption flow completes the loop.
use base64::encode; // (bytes: slice(u8)) -> Str
use base64::decode; // (s: Str) -> opt(Vec[u8])
use base64::encode_url; // (bytes: slice(u8)) -> Str
use base64::decode_url; // (s: Str) -> opt(Vec[u8])
Alphabet and padding (RFC 4648):
encode / decode §4 standard alphabet (A-Za-z0-9+/), '=' padding
encode_url / decode_url §5 URL-safe alphabet (A-Za-z0-9-_), no padding
decode and decode_url return None on any invalid input: characters
outside the chosen alphabet, malformed padding (for the standard form),
or truncated quanta.
use base64::encode;
use base64::decode;
use io::println;
fn main() -> i32 {
let raw: slice(u8) = b"fastC v1.0";
let s: Str = encode(raw); // "ZmFzdEMgdjEuMA=="
println(s.as_cstr());
let round: opt(Vec[u8]) = decode(s);
if (round.is_none()) {
return 1;
}
let back: Vec[u8] = round.unwrap();
if (back.as_slice() != raw) {
return 1;
}
return 0;
}
Pure data transform — no Cap* token required. encode, decode,
encode_url, and decode_url touch no syscalls, no clock, no
filesystem, no network. They allocate a Str or Vec[u8] and that
is the entire side effect.
v0.1.0 — preview. API is final; the package becomes a true
installable via fastc add once the consumption flow ships. Until
then, the same API is available in every fastC v1.0 program via
the built-in prelude.
MIT