Stdlibencoding
base64
import std::encoding::base64; · source
Base64
function encode(data: u8*, len: u64) -> String;
function decode(source: Str) -> Option<Array<u8>>;
RFC 4648, standard alphabet, with padding.
import std::encoding::base64;
mut text: String = encode(bytes.as_ptr(), bytes.length());
match (decode(text.as_str())) {
Option::Some(raw) => { /* Array<u8> */ }
Option::None => { /* malformed input */ }
}
encode encodes len bytes into a padded base64 string you own.
decode returns None on any invalid character or a malformed length. Whitespace is not tolerated — strip line breaks before calling if the input came from a wrapped MIME body.