Base64 Stream
To encode/decode large data with the standard Base64 encoding.
Examples
Encode
ToBase64Reader
extern crate base64_stream;
use ;
use ToBase64Reader;
let test_data = b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".to_vec;
let mut reader = new;
let mut base64 = String new;
reader.read_to_string.unwrap;
assert_eq!;
ToBase64Writer
extern crate base64_stream;
use ;
use Write;
use Path;
use ToBase64Writer;
const DATA_FOLDER: &str = "data";
const ENCODE_OUTPUT: &str = "encode_output.txt";
let test_data = b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".as_ref;
let file_path = new.join.join;
let base64 = create.unwrap;
let mut writer = new;
writer.write_all.unwrap;
writer.flush.unwrap; // the flush method is only used when the full plain data has been written
assert_eq!;
Decode
FromBase64Reader
extern crate base64_stream;
use Cursor;
use Read;
use FromBase64Reader;
let base64 = b"SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==".to_vec;
let mut reader = new;
let mut test_data = String new;
reader.read_to_string.unwrap;
assert_eq!;
FromBase64Writer
extern crate base64_stream;
use ;
use Write;
use Path;
use FromBase64Writer;
const DATA_FOLDER: &str = "data";
const DECODE_OUTPUT: &str = "decode_output.txt";
let base64 = b"SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==".as_ref;
let file_path = new.join.join;
let test_data = create.unwrap;
let mut writer = new;
writer.write_all.unwrap;
writer.flush.unwrap; // the flush method is only used when the full base64 data has been written
assert_eq!;
Change the Buffer Size
The default buffer size is 4096 bytes. If you want to change that, you can use the new2
associated function and define a length explicitly to create an instance of the above structs.
For example, to change the buffer size to 256 bytes,
extern crate base64_stream;
use ;
use ToBase64Reader;
use U256;
let test_data = b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".to_vec;
let mut reader: = new2;
let mut base64 = String new;
reader.read_to_string.unwrap;
assert_eq!;
Crates.io
https://crates.io/crates/base64-stream