To encode/decode large data with the standard Base64 encoding.
```rust use std::io::{Cursor, 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 = String::new();
reader.readtostring(&mut base64).unwrap();
assert_eq!("SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==", base64); ```
```rust use std::fs::{self, File}; use std::io::Write; use std::path::Path;
use base64_stream::ToBase64Writer;
const DATAFOLDER: &str = "data"; const ENCODEOUTPUT: &str = "encode_output.txt";
let testdata = b"Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.".asref();
let filepath = Path::new("tests").join(DATAFOLDER).join(ENCODE_OUTPUT);
let base64 = File::create(filepath.aspath()).unwrap();
let mut writer = ToBase64Writer::new(base64);
writer.writeall(testdata).unwrap();
writer.flush().unwrap(); // the flush method is only used when the full plain data has been written
asserteq!("SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==", fs::readtostring(filepath).unwrap()); ```
```rust 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 = String::new();
reader.readtostring(&mut test_data).unwrap();
asserteq!("Hi there, this is a simple sentence used for testing this crate. I hope all cases are correct.", testdata); ```
```rust use std::fs::{self, File}; use std::io::Write; use std::path::Path;
use base64_stream::FromBase64Writer;
const DATAFOLDER: &str = "data"; const DECODEOUTPUT: &str = "decode_output.txt";
let base64 = b"SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==".as_ref();
let filepath = Path::new("tests").join(DATAFOLDER).join(DECODE_OUTPUT);
let testdata = File::create(filepath.as_path()).unwrap();
let mut writer = FromBase64Writer::new(test_data);
writer.write_all(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(filepath).unwrap()); ```
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,
```rust use std::io::{Cursor, Read};
use base64stream::ToBase64Reader; use base64stream::generic_array::typenum::U256;
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<_, U256> = ToBase64Reader::new2(Cursor::new(test_data));
let mut base64 = String::new();
reader.readtostring(&mut base64).unwrap();
assert_eq!("SGkgdGhlcmUsIHRoaXMgaXMgYSBzaW1wbGUgc2VudGVuY2UgdXNlZCBmb3IgdGVzdGluZyB0aGlzIGNyYXRlLiBJIGhvcGUgYWxsIGNhc2VzIGFyZSBjb3JyZWN0Lg==", base64); ```
https://crates.io/crates/base64-stream
https://docs.rs/base64-stream