zx0

Struct Compressor

Source
pub struct Compressor<'a> { /* private fields */ }
Expand description

This struct provides a means of initializing and performing a ZX0 compression operation by leveraging the builder pattern.

By calling Compressor::new a new Compressor will be instantiated using the following default values:

  • No prefix/suffix skipping
  • Quick mode disabled
  • Backwards mode disabled
  • Classic mode disabled

After constructing a Compressor instance the method compress is available to compress u8 slices. The Compressor can be resued again afterwards.

In contrast to the original C implementation, compression using the Rust ZX0 compressor is thread-safe, and can therefore be used to compress several slices in parallel.

Implementations§

Source§

impl<'a> Compressor<'a>

Source

pub fn new() -> Self

Instantiate a new Compressor using the following default values:

  • No prefix/suffix skipping
  • Quick mode disabled
  • Backwards mode disabled
  • Classic mode disabled
Source

pub fn quick_mode(&mut self, quick_mode: bool) -> &mut Self

Change the value for the quick mode setting. When enabled, this will cause the ZX0 compressor to use a smaller dictionary size, at the cost of a less efficient compression ratio.

Enabling this setting can be useful when producing debug assets where a short feedback loop is more important than getting a good compression ratio.

Source

pub fn backwards_mode(&mut self, backwards_mode: bool) -> &mut Self

Change the value for the backwards compression mode setting. This will cause the ZX0 compressor to create compressed data that should be decompressed back-to-front. This can be useful in situations where in-place decompression is desired, and the end of the compressed data overlaps with the end of the region that the uncompressed data should be positioned in.

Please refer to the original C implementation’s readme for an in-depth explanation.

Source

pub fn classic_mode(&mut self, classic_mode: bool) -> &mut Self

Change the value for the classic compression mode setting. Enabling this will cause the ZX0 compressor to output compressed data in its legacy V1 file format. This can be useful when compressing for one of the platforms that only provides a V1 decompression routine.

Source

pub fn progress_callback<C: FnMut(f32) + 'a>( &mut self, progress_callback: C, ) -> &mut Self

Set a progress callback. When providing a closure to this function, that closure will be called repeatedly during compression. The closure will be called with a progress value between 0.0 and 1.0. Note that due to the nature of the compression algorithm, this value is not increasing linearly with time, and thus should be interpreted as a rough estimate.

Source

pub fn skip(&mut self, skip: usize) -> &mut Self

Set the number of prefix/suffix bytes to skip during compression. This will cause the compressor to create a dictionary based on data that will already be in memory before the compressed data during decompression. Of course, for this to work the prefix (or suffix in case of backwards mode) in the file must be 100% identical to the data that is in memory before or after the block of compressed data when attempting to decompress it.

Please refer to the original C implementation’s readme for an in-depth explanation.

Source

pub fn compress(&mut self, input: &[u8]) -> CompressionResult

Compress the provided slice.

This returns a CompressionResult struct containing both the compressed data as well as metadata related to the compression operation.

The Compressor does not have to be discarded after calling this method. It does not contain any state (only the configuration) and thus can be reused again for compressing additional data.

Trait Implementations§

Source§

impl<'a> Default for Compressor<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Compressor<'a>

§

impl<'a> !RefUnwindSafe for Compressor<'a>

§

impl<'a> !Send for Compressor<'a>

§

impl<'a> !Sync for Compressor<'a>

§

impl<'a> Unpin for Compressor<'a>

§

impl<'a> !UnwindSafe for Compressor<'a>

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.