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

A builder-style struct that configures compression settings. This is how you compress LZ4 frames. (An LZ4 file usually consists of a single frame.)

Create it using Default::default().

Implementations§

source§

impl<'a> CompressionSettings<'a>

source

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

In independent mode, blocks are not allowed to reference data from previous blocks. Hence, using dependent blocks yields slightly better compression. The downside of dependent blocks is that seeking becomes impossible - the entire frame always has to be decompressed from the beginning.

Blocks are independent by default.

source

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

Block checksums can help detect data corruption in storage and transit. They do not offer error correction though.

In most cases, block checksums are not very helpful because you generally want a lower layer to deal with data corruption more comprehensively.

Block checksums are disabled by default.

source

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

The content checksum (also called frame checksum) is calculated over the contents of the entire frame. This makes them cheaper than block checksums as their size overhead is constant as well as marginally more useful, because they can help protect against incorrect decompression.

Note that the content checksum can only be verified after the entire frame has been read (and returned!), which is the downside of content checksums.

Frame checksums are enabled by default.

source

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

Only valid values are 4MiB, 1MiB, 256KiB, 64KiB (TODO: better interface for this)

The default block size is 4 MiB.

source

pub fn dictionary(&mut self, id: u32, dict: &'a [u8]) -> &mut Self

A dictionary is essentially a constant slice of bytes shared by the compressing and decompressing party. Using a dictionary can improve compression ratios, because the compressor can reference data from the dictionary.

The dictionary id is an application-specific identifier which can be used during decompression to determine which dictionary to use.

Note that while the size of a dictionary can be arbitrary, dictionaries larger than 64 KiB are not useful as the LZ4 algorithm does not support backreferences by more than 64 KiB, i.e. any dictionary content before the trailing 64 KiB is silently ignored.

By default, no dictionary is used and no id is specified.

source

pub fn dictionary_id_nonsense_override(&mut self, id: Option<u32>) -> &mut Self

The dictionary id header field is quite obviously intended to tell anyone trying to decompress your frame which dictionary to use. So it is only natural to assume that the absence of a dictionary id indicates that no dictionary was used.

Unfortunately this assumption turns out to be incorrect. The LZ4 CLI simply never writes a dictionary id. The major downside is that you can no longer distinguish corrupted data from a missing dictionary (unless you write block checksums, which the LZ4 CLI also never does).

Hence, this library is opinionated in the sense that we always want you to specify either neither or both of these things (the LZ4 CLI basically just ignores the dictionary id completely and only cares about whether you specify a dictionary parameter or not).

If you think you know better (you probably don’t) you may use this method to break this rule.

source

pub fn compress<R: Read, W: Write>( &self, reader: R, writer: W ) -> Result<(), CompressionError>

source

pub fn compress_with_size_unchecked<R: Read, W: Write>( &self, reader: R, writer: W, content_size: u64 ) -> Result<(), CompressionError>

source

pub fn compress_with_size<R: Read + Seek, W: Write>( &self, reader: R, writer: W ) -> Result<(), CompressionError>

Trait Implementations§

source§

impl<'a> Default for CompressionSettings<'a>

source§

fn default() -> Self

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

Auto Trait Implementations§

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>,

§

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>,

§

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.