Base64 binary-to-text encoding

Trait FromBase64

Method from_base64

fn from_base64(&self) -> ~[u8]

Trait ToBase64

A trait for converting a value to base64 encoding.

Method to_base64

fn to_base64(&self) -> ~str

Converts the value of self to a base64 value, returning the owned string

Implementation of ToBase64 for &'self [u8] where <'self>

Method to_base64

fn to_base64(&self) -> ~str

Turn a vector of u8 bytes into a base64 string.

Example

extern mod extra;
use extra::base64::ToBase64;

fn main () {
    let str = [52,32].to_base64();
    println(fmt!("%s", str));
}

Implementation of ToBase64 for &'self str where <'self>

Method to_base64

fn to_base64(&self) -> ~str

Convert any string (literal, @, &, or ~) to base64 encoding.

Example

extern mod extra;
use extra::base64::ToBase64;

fn main () {
    let str = "Hello, World".to_base64();
    println(fmt!("%s",str));
}

Implementation of FromBase64 for &'self [u8] where <'self>

Method 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.

Example

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));
}

Implementation of FromBase64 for &'self str where <'self>

Method 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.

Example

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));
}