There's more...

The current encode_something and decode_something functions are designed to be as simple to use as possible. However, they waste some performance by allocating Vec<u8> even though we could pipe the data directly into a writer. When writing a library, it would be nice to give the user both possibilities by adding methods in this way:

use std::io::Write;
fn encode_file_into(file: &mut Read, target: &mut Write) -> io::Result<()> {
// Files have a built-in encoder
let mut encoded = file.zlib_encode(Compression::Best);
io::copy(&mut encoded, target)?;
Ok(())
}

The user could call them like this:

// Compress it
encode_file_into(&mut original_reader, &mut encoded_writer)
.expect("Failed to encode file");
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.169.109