Struct Encoder

Source
pub struct Encoder { /* private fields */ }
Expand description

Encoder for Blosc compression.

This struct is not the usual stream-like encoder that commonly exists in Rust compression libraries, but rather a configuration builder for the Blosc compression. This is because blosc is not a streaming compression library, and it operate on the entire data buffer at once.

Implementations§

Source§

impl Encoder

Source

pub fn new(level: Level) -> Self

Create a new encoder with the specified compression level.

Source

pub fn level(&mut self, level: Level) -> &mut Self

Sets the compression level for the encoder.

Source

pub fn shuffle(&mut self, shuffle: Shuffle) -> &mut Self

Sets which (if any) shuffle compression filters should be applied.

By default, the shuffle filter is set to Shuffle::Byte.

Source

pub fn typesize(&mut self, typesize: NonZeroUsize) -> &mut Self

Sets the typesize for the encoder.

This is the number of bytes for the atomic type in the binary src buffer. For implementation reasons, only a typesize in the range 1 < typesize < 256 will allow the shuffle filter to work. When typesize is not in this range, shuffle will be silently disabled.

The typesize is also used to split the input bytes into logical items, and a Decoder can access these items by their index without decompressing the entire buffer. See Decoder::item and Decoder::items.

By default, the typesize is set to 1.

Source

pub fn compressor(&mut self, compressor: CompressAlgo) -> &mut Self

Sets the compression algorithm to use.

By default, the compression algorithm is set to CompressAlgo::Blosclz.

Source

pub fn blocksize(&mut self, blocksize: Option<NonZeroUsize>) -> &mut Self

Sets the block size for compression.

If None, an automatic block size will be used. By default, the block size is set to None.

Source

pub fn numinternalthreads(&mut self, numinternalthreads: u32) -> &mut Self

Sets the number of threads to use internally for compression.

By default, the number of internal threads is set to 1.

Source

pub fn compress(&self, src: &[u8]) -> Result<Vec<u8>, CompressError>

Compress a block of data in the src buffer and returns the compressed data.

Note that this function allocates a new Vec<u8> for the compressed data with the maximum possible size required for it (uncompressed size + 16), which may be larger than whats actually needed. If this function is used in a critical performance path, consider using compress_into instead, allowing you to provide a pre-allocated buffer which can be used repeatedly without the overhead of allocations.

Source

pub fn compress_into( &self, src: &[u8], dst: &mut [MaybeUninit<u8>], ) -> Result<usize, CompressError>

Compress a block of data in the src buffer into the dst buffer.

§Returns

The number of bytes copied into the destination buffer.

Trait Implementations§

Source§

impl Default for Encoder

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

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.