ruzstd::encoding

Struct FrameCompressor

Source
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:

  1. Initializing a compressor by providing a buffer of data using FrameCompressor::new()
  2. 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>

Source

pub fn new(compression_level: CompressionLevel) -> Self

Create a new FrameCompressor

Source§

impl<R: Read, W: Write, M: Matcher> FrameCompressor<R, W, M>

Source

pub fn new_with_matcher(matcher: M, compression_level: CompressionLevel) -> Self

Create a new FrameCompressor with a custom matching algorithm implementation

Source

pub fn set_source(&mut self, uncompressed_data: R) -> Option<R>

Before calling FrameCompressor::compress you need to set the source

Source

pub fn set_drain(&mut self, compressed_data: W) -> Option<W>

Before calling FrameCompressor::compress you need to set the drain

Source

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

Source

pub fn source_mut(&mut self) -> Option<&mut R>

Get a mutable reference to the source

Source

pub fn drain_mut(&mut self) -> Option<&mut W>

Get a mutable reference to the drain

Source

pub fn source(&self) -> Option<&R>

Get a reference to the source

Source

pub fn drain(&self) -> Option<&W>

Get a reference to the drain

Source

pub fn take_source(&mut self) -> Option<R>

Retrieve the source

Source

pub fn take_drain(&mut self) -> Option<W>

Retrieve the drain

Source

pub fn replace_matcher(&mut self, match_generator: M) -> M

Before calling FrameCompressor::compress you can replace the matcher

Source

pub fn set_compression_level( &mut self, compression_level: CompressionLevel, ) -> CompressionLevel

Before calling FrameCompressor::compress you can replace the compression level

Source

pub fn compression_level(&self) -> CompressionLevel

Get the current compression level

Auto Trait Implementations§

§

impl<R, W, M> Freeze for FrameCompressor<R, W, M>
where M: Freeze, R: Freeze, W: Freeze,

§

impl<R, W, M> RefUnwindSafe for FrameCompressor<R, W, M>

§

impl<R, W, M> Send for FrameCompressor<R, W, M>
where M: Send, R: Send, W: Send,

§

impl<R, W, M> Sync for FrameCompressor<R, W, M>
where M: Sync, R: Sync, W: Sync,

§

impl<R, W, M> Unpin for FrameCompressor<R, W, M>
where M: Unpin, R: Unpin, W: Unpin,

§

impl<R, W, M> UnwindSafe for FrameCompressor<R, W, M>
where M: UnwindSafe, R: UnwindSafe, W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.