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
impl Encoder
Sourcepub fn shuffle(&mut self, shuffle: Shuffle) -> &mut Self
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
.
Sourcepub fn typesize(&mut self, typesize: NonZeroUsize) -> &mut Self
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.
Sourcepub fn compressor(&mut self, compressor: CompressAlgo) -> &mut Self
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
.
Sourcepub fn blocksize(&mut self, blocksize: Option<NonZeroUsize>) -> &mut Self
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
.
Sourcepub fn numinternalthreads(&mut self, numinternalthreads: u32) -> &mut Self
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.
Sourcepub fn compress(&self, src: &[u8]) -> Result<Vec<u8>, CompressError>
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.
Sourcepub fn compress_into(
&self,
src: &[u8],
dst: &mut [MaybeUninit<u8>],
) -> Result<usize, CompressError>
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.