Crate basic64

Crate basic64 

Source
Expand description

§Usage

use std::io::{self, Read};

use basic64;

fn main() {
    let mut handle = io::stdin().lock();

    let mut input = [0u8; basic64::round_len!(dec 8_192)];
    // !
    let mut encoded = String::with_capacity(basic64::needed_len!(enc input.len()));

    while let Ok(n) = handle.read(&mut input) {
        if n == 0 {
            break;
        }

        // !
        basic64::encode_into(&input[..n], &mut encoded);
        print!("{}", encoded);
        encoded.clear();
    }

    println!("");
}

Macros§

needed_len
Returns the needed length for a buffer to (en/de)code up to len bytes.
round_len
Rounds up len to be an exact (en/de)coding buffer length.

Functions§

decode
Decodes as much from input as possible; returns a newly allocated Vec<u8>.
decode_into
Decodes a base64-encoded string from input appending the result to output while there are valid characters; returns the number of decoded bytes.
encode
Encode input to base64, returning a newly allocated String.
encode_into
Encode input to base64, appending the result to buffer.