pub struct FrameCompressor<R: Read, W: Write, M: Matcher> { /* private fields */ }
Expand description
An interface for compressing arbitrary data with the ZStandard compression algorithm.
FrameCompressor
will generally be used by:
- Initializing a compressor by providing a buffer of data using
FrameCompressor::new()
- Starting compression and writing that compression into a vec using
FrameCompressor::begin
§Examples
use ruzstd::encoding::{FrameCompressor, CompressionLevel};
let mock_data: &[_] = &[0x1, 0x2, 0x3, 0x4];
let mut output = std::vec::Vec::new();
// Initialize a compressor.
let mut compressor = FrameCompressor::new(CompressionLevel::Uncompressed);
compressor.set_source(mock_data);
compressor.set_drain(&mut output);
// `compress` writes the compressed output into the provided buffer.
compressor.compress();
Implementations§
Source§impl<R: Read, W: Write> FrameCompressor<R, W, MatchGeneratorDriver>
impl<R: Read, W: Write> FrameCompressor<R, W, MatchGeneratorDriver>
Sourcepub fn new(compression_level: CompressionLevel) -> Self
pub fn new(compression_level: CompressionLevel) -> Self
Create a new FrameCompressor
Source§impl<R: Read, W: Write, M: Matcher> FrameCompressor<R, W, M>
impl<R: Read, W: Write, M: Matcher> FrameCompressor<R, W, M>
Sourcepub fn new_with_matcher(matcher: M, compression_level: CompressionLevel) -> Self
pub fn new_with_matcher(matcher: M, compression_level: CompressionLevel) -> Self
Create a new FrameCompressor
with a custom matching algorithm implementation
Sourcepub fn set_source(&mut self, uncompressed_data: R) -> Option<R>
pub fn set_source(&mut self, uncompressed_data: R) -> Option<R>
Before calling FrameCompressor::compress you need to set the source
Sourcepub fn set_drain(&mut self, compressed_data: W) -> Option<W>
pub fn set_drain(&mut self, compressed_data: W) -> Option<W>
Before calling FrameCompressor::compress you need to set the drain
Sourcepub fn compress(&mut self)
pub fn compress(&mut self)
Compress the uncompressed data from the provided source as one Zstd frame and write it to the provided drain
This will repeatedly call Read::read on the source to fill up blocks until the source returns 0 on the read call. Also Write::write_all will be called on the drain after each block has been encoded.
To avoid endlessly encoding from a potentially endless source (like a network socket) you can use the Read::take function
Sourcepub fn source_mut(&mut self) -> Option<&mut R>
pub fn source_mut(&mut self) -> Option<&mut R>
Get a mutable reference to the source
Sourcepub fn take_source(&mut self) -> Option<R>
pub fn take_source(&mut self) -> Option<R>
Retrieve the source
Sourcepub fn take_drain(&mut self) -> Option<W>
pub fn take_drain(&mut self) -> Option<W>
Retrieve the drain
Sourcepub fn replace_matcher(&mut self, match_generator: M) -> M
pub fn replace_matcher(&mut self, match_generator: M) -> M
Before calling FrameCompressor::compress you can replace the matcher
Sourcepub fn set_compression_level(
&mut self,
compression_level: CompressionLevel,
) -> CompressionLevel
pub fn set_compression_level( &mut self, compression_level: CompressionLevel, ) -> CompressionLevel
Before calling FrameCompressor::compress you can replace the compression level
Sourcepub fn compression_level(&self) -> CompressionLevel
pub fn compression_level(&self) -> CompressionLevel
Get the current compression level