Base64 binary-to-text encoding
FromBase64
ToBase64
- A trait for converting a value to base64 encoding.of ToBase64 for &'self [u8] where <'self>
of ToBase64 for &'self str where <'self>
of FromBase64 for &'self [u8] where <'self>
of FromBase64 for &'self str where <'self>
FromBase64
from_base64
fn from_base64(&self) -> ~[u8]
ToBase64
A trait for converting a value to base64 encoding.
to_base64
fn to_base64(&self) -> ~str
Converts the value of self
to a base64 value, returning the owned string
ToBase64
for &'self [u8]
where <'self>
to_base64
fn to_base64(&self) -> ~str
Turn a vector of u8
bytes into a base64 string.
extern mod extra;
use extra::base64::ToBase64;
fn main () {
let str = [52,32].to_base64();
println(fmt!("%s", str));
}
ToBase64
for &'self str
where <'self>
to_base64
fn to_base64(&self) -> ~str
Convert any string (literal, @
, &
, or ~
) to base64 encoding.
extern mod extra;
use extra::base64::ToBase64;
fn main () {
let str = "Hello, World".to_base64();
println(fmt!("%s",str));
}
FromBase64
for &'self [u8]
where <'self>
from_base64
fn from_base64(&self) -> ~[u8]
Convert base64 u8
vector into u8 byte values. Every 4 encoded characters is converted into 3 octets, modulo padding.
extern mod extra;
use extra::base64::ToBase64;
use extra::base64::FromBase64;
fn main () {
let str = [52,32].to_base64();
println(fmt!("%s", str));
let bytes = str.from_base64();
println(fmt!("%?",bytes));
}
FromBase64
for &'self str
where <'self>
from_base64
fn from_base64(&self) -> ~[u8]
Convert any base64 encoded string (literal, @
, &
, or ~
) to the byte values it encodes.
You can use the from_bytes
function in std::str
to turn a [u8]
into a string with characters corresponding to those values.
This converts a string literal to base64 and back.
extern mod extra;
use extra::base64::ToBase64;
use extra::base64::FromBase64;
use std::str;
fn main () {
let hello_str = "Hello, World".to_base64();
println(fmt!("%s",hello_str));
let bytes = hello_str.from_base64();
println(fmt!("%?",bytes));
let result_str = str::from_bytes(bytes);
println(fmt!("%s",result_str));
}