Struct DeflateEncoder
pub struct DeflateEncoder<R> { /* private fields */ }
A DEFLATE encoder, or compressor.
This structure implements a Read interface. When read from, it reads
uncompressed data from the underlying Read and provides the compressed data.
Examples
use std::io::prelude::*;
use std::io;
use flate2::Compression;
use flate2::read::DeflateEncoder;
# fn main() {
# println!("{:?}", deflateencoder_read_hello_world().unwrap());
# }
#
// Return a vector containing the Deflate compressed version of hello world
fn deflateencoder_read_hello_world() -> io::Result<Vec<u8>> {
let mut ret_vec = Vec::new();
let c = b"hello world";
let mut deflater = DeflateEncoder::new(&c[..], Compression::fast());
deflater.read_to_end(&mut ret_vec)?;
Ok(ret_vec)
}
Implementations
impl<R> DeflateEncoder<R>
fn reset(&mut self, r: R) -> RResets the state of this encoder entirely, swapping out the input stream for another.
This function will reset the internal state of this encoder and replace the input stream with the one provided, returning the previous input stream. Future data read from this encoder will be the compressed version of
r's data.Note that there may be currently buffered data when this function is called, and in that case the buffered data is discarded.
fn get_ref(&self) -> &RAcquires a reference to the underlying reader
fn get_mut(&mut self) -> &mut RAcquires a mutable reference to the underlying stream
The underlying reader may be mutated as long as its unread input and current position are preserved for subsequent reads by this encoder.
To process a new stream, wait for this encoder to reach EOF and use
reset; replacing the reader directly does not reset it.fn into_inner(self) -> RConsumes this encoder, returning the underlying reader.
Note that there may be buffered bytes which are not re-acquired as part of this transition. It's recommended to only call this function after EOF has been reached.
fn total_in(&self) -> u64Returns the number of bytes that have been read into this compressor.
Note that not all bytes read from the underlying object may be accounted for, there may still be some active buffering.
fn total_out(&self) -> u64Returns the number of bytes that the compressor has produced.
Note that not all bytes may have been read yet, some may still be buffered.
impl<R: Read> DeflateEncoder<R>
fn new(r: R, level: Compression) -> DeflateEncoder<R>Creates a new encoder which will read uncompressed data from the given stream and emit the compressed stream.
Trait Implementations
impl<R: Debug> Debug for DeflateEncoder<R>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<R: Read> Read for DeflateEncoder<R>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
impl<W: Read + Write> Write for DeflateEncoder<W>
fn write(&mut self, buf: &[u8]) -> Result<usize>fn flush(&mut self) -> Result<()>