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.

Function b64_char

fn b64_char(idx: i32, url_safe: bool) -> i32

Map a 6-bit index (0–63) to its Base64 ASCII code.

Function encode_impl

fn encode_impl(data: bytes, url_safe: bool) -> String

Encode binary data to a Base64 string using the standard or URL-safe alphabet.

Function decode_char

fn decode_char(ch: String) -> i32

Map a single-character string to its 6-bit Base64 value. Returns -1 for invalid characters.