Base64 Stream

Build Status

Base64 Stream

To encode/decode large data with the standard Base64 encoding.

Examples

Encode

ToBase64Reader

```rust extern crate base64_stream;

use std::io::Cursor;

use std::io::Read;

use base64_stream::ToBase64Reader;

let testdata = b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".tovec();

let mut reader = ToBase64Reader::new(Cursor::new(test_data));

let mut base64 = [0u8; 4096];

let c = reader.read(&mut base64).unwrap();

asserteq!(b"SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==".tovec(), base64[..c].to_vec()); ```

ToBase64Writer

```rust extern crate base64_stream;

use std::fs::{self, File};

use std::io::Write;

use base64_stream::ToBase64Writer;

let testdata = b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".asref();

let base64 = File::create("encode_output.txt").unwrap();

let mut writer = ToBase64Writer::new(base64);

writer.write(test_data).unwrap();

writer.flush().unwrap(); // the flush method is only used when the full base64 data has been written

drop(writer);

asserteq!("SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==", fs::readtostring("encodeoutput.txt").unwrap()); ```

Decode

FromBase64Reader

```rust extern crate base64_stream;

use std::io::Cursor;

use std::io::Read;

use base64_stream::FromBase64Reader;

let base64 = b"SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==".to_vec();

let mut reader = FromBase64Reader::new(Cursor::new(base64));

let mut test_data = [0u8; 4096];

let c = reader.read(&mut test_data).unwrap();

asserteq!(b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".tovec(), testdata[..c].tovec()); ```

FromBase64Writer

```rust extern crate base64_stream;

use std::fs::{self, File};

use std::io::Write;

use base64_stream::FromBase64Writer;

let base64 = b"SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==".as_ref();

let testdata = File::create("decodeoutput.txt").unwrap();

let mut writer = FromBase64Writer::new(test_data);

writer.write(base64).unwrap();

writer.flush().unwrap(); // the flush method is only used when the full base64 data has been written

asserteq!("Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.", fs::readtostring("decodeoutput.txt").unwrap()); ```

Crates.io

https://crates.io/crates/base64-stream

Documentation

https://docs.rs/base64-stream

License

MIT