Module std::encoding::base64

Base64 encoding and decoding โ€” pure Hew implementation.

Encode binary data to Base64 strings and decode Base64 strings back to binary data. Supports both standard and URL-safe alphabets.

Examples

import std::encoding::base64;

fn main() {
    let data: bytes = bytes::new();
    data.push(72);   // H
    data.push(105);  // i
    let s = base64.encode(data);
    println(s);   // "SGk="
    let back = base64.decode(s);
    println(back.len());  // 2
}

Contents

Functions

Function encode

pub fn encode(data: bytes) -> string

Encode binary data to a standard Base64 string.

Function encode_url

pub fn encode_url(data: bytes) -> string

Encode binary data to a URL-safe Base64 string.

Function decode

pub fn decode(s: string) -> bytes

Decode a Base64 string to binary data.

Returns an empty bytes buffer if the input is not valid Base64.