pub struct Encoder { /* private fields */ }Expand description
A streaming zlib encoder.
§Examples
use compress_lib::{Level, deflate::Flush, zlib};
let mut enc = zlib::Encoder::new(Level::DEFAULT);
let mut packed = Vec::new();
enc.compress_vec(b"part one, ", &mut packed, Flush::None)?;
enc.compress_vec(b"part two", &mut packed, Flush::Finish)?;
assert_eq!(zlib::decompress(&packed)?, b"part one, part two");Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn new(level: Level) -> Self
pub fn new(level: Level) -> Self
An encoder at level with window bits 15.
§Examples
let enc = compress_lib::zlib::Encoder::new(compress_lib::Level::FAST);Sourcepub fn with_window_bits(self, bits: u8) -> Result<Self, Error>
pub fn with_window_bits(self, bits: u8) -> Result<Self, Error>
Sets the window to 2^bits bytes, 8 to 15 (the header names it;
zlib’s own encoder rounds 8 up to 9, this one does not).
§Errors
ErrorKind::InvalidWindowBits outside 8 to 15.
§Examples
use compress_lib::{Level, deflate::Flush, zlib};
let mut enc = zlib::Encoder::new(Level::DEFAULT).with_window_bits(10)?;
let mut packed = Vec::new();
enc.compress_vec(b"x", &mut packed, Flush::Finish)?;
assert_eq!(packed[0], 0x28);Sourcepub fn set_dictionary(&mut self, dictionary: &[u8]) -> Result<(), Error>
pub fn set_dictionary(&mut self, dictionary: &[u8]) -> Result<(), Error>
Presets a dictionary; the header then names it (FDICT) and the decoder must be given the same one. Only before any input.
§Errors
ErrorKind::InvalidState after input has been given.
§Examples
let mut enc = compress_lib::zlib::Encoder::default();
enc.set_dictionary(b"dictionary")?;Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Starts a new stream, keeping allocations (and no dictionary).
§Examples
let mut enc = compress_lib::zlib::Encoder::default();
enc.reset();Sourcepub fn total_in(&self) -> u64
pub fn total_in(&self) -> u64
Uncompressed bytes taken.
§Examples
use compress_lib::{deflate::Flush, zlib};
let mut enc = zlib::Encoder::default();
enc.compress_vec(b"abc", &mut Vec::new(), Flush::Finish)?;
assert_eq!(enc.total_in(), 3);Sourcepub fn memory_in_use(&self) -> usize
pub fn memory_in_use(&self) -> usize
Sourcepub fn compress(
&mut self,
input: &[u8],
output: &mut [u8],
flush: Flush,
) -> Result<Progress, Error>
pub fn compress( &mut self, input: &[u8], output: &mut [u8], flush: Flush, ) -> Result<Progress, Error>
As Deflater::compress, with the header written first and the
Adler-32 trailer after Finish.
§Errors
As Deflater::compress.
§Examples
use compress_lib::{deflate::{Flush, Status}, zlib};
let mut enc = zlib::Encoder::default();
let mut out = [0u8; 64];
let p = enc.compress(b"abc", &mut out, Flush::Finish)?;
assert_eq!(p.status, Status::Done);
assert_eq!(zlib::decompress(&out[..p.produced])?, b"abc");Sourcepub fn compress_vec(
&mut self,
input: &[u8],
out: &mut Vec<u8>,
flush: Flush,
) -> Result<Progress, Error>
pub fn compress_vec( &mut self, input: &[u8], out: &mut Vec<u8>, flush: Flush, ) -> Result<Progress, Error>
As compress, appending to out until the
flush point is written.
§Errors
As compress, plus AllocationFailed.
§Examples
use compress_lib::{deflate::Flush, zlib};
let mut out = Vec::new();
zlib::Encoder::default().compress_vec(b"abc", &mut out, Flush::Finish)?;
assert_eq!(zlib::decompress(&out)?, b"abc");Trait Implementations§
Auto Trait Implementations§
impl Forget for Encoder
impl Freeze for Encoder
impl RefUnwindSafe for Encoder
impl Send for Encoder
impl Sync for Encoder
impl Unpin for Encoder
impl UnsafeUnpin for Encoder
impl UnwindSafe for Encoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more