std.base64
Base64 (RFC 4648), the standard alphabet with = padding:
import std.base64
let text = base64.encode("hello".bytes()) // "aGVsbG8="
let bytes = base64.decode(text)?
print(string_from_bytes(bytes))encode_text and decode_text do the same for strings.
Functions
fn encode
pub fn encode(data: List[u8]) -> stringfn encode_text
pub fn encode_text(text: string) -> stringThe UTF-8 bytes of text, encoded.
fn decode
pub fn decode(text: string) -> Result[List[u8], string]The bytes of base64 text; spaces and line breaks are skipped.
fn decode_text
pub fn decode_text(text: string) -> Result[string, string]Decoded bytes as a string, which must be UTF-8.