pub struct Chunk<'a> { /* private fields */ }Expand description
A chunk of compressed data.
A chunk is a thin wrapper around CowVec<u8>, with some additional metadata, and the creation
of a Chunk through the Self::from_compressed is very cheap.
Implementations§
Source§impl<'a> Chunk<'a>
impl<'a> Chunk<'a>
Sourcepub fn from_compressed(bytes: CowVec<'a, u8>) -> Result<Self, Error>
pub fn from_compressed(bytes: CowVec<'a, u8>) -> Result<Self, Error>
Create a new Chunk from a compressed bytes buffer.
Sourcepub fn into_bytes(self) -> CowVec<'a, u8>
pub fn into_bytes(self) -> CowVec<'a, u8>
Convert the chunk into a bytes buffer.
Sourcepub fn get_dparams(&self) -> DParams
pub fn get_dparams(&self) -> DParams
Get the current decompression parameters.
Sourcepub fn set_dparams(&self, params: DParams) -> Result<(), Error>
pub fn set_dparams(&self, params: DParams) -> Result<(), Error>
Set the decompression parameters.
Sourcepub fn decompress(&self) -> Result<Vec<u8>, Error>
pub fn decompress(&self) -> Result<Vec<u8>, Error>
Decompress the whole chunk into a new allocated bytes vector.
For decompressing the data into an already allocated buffer, create a Decoder
(with other params or Self::get_dparams) and use Decoder::decompress_into.
Sourcepub fn item(&self, idx: usize) -> Result<Vec<u8>, Error>
pub fn item(&self, idx: usize) -> Result<Vec<u8>, Error>
Get an item at the specified index.
Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.
Note that the returned vector may not be aligned to the original data type’s alignment, and the caller should
ensure that the alignment is correct before transmuting it to original type. If the alignment does not match
the original data type, the bytes should be copied to a new aligned allocation before transmuting, otherwise
undefined behavior may occur. Alternatively, the caller can use Self::item_into and provide an already
aligned destination buffer.
Sourcepub fn item_into(
&self,
idx: usize,
dst: &mut [MaybeUninit<u8>],
) -> Result<usize, Error>
pub fn item_into( &self, idx: usize, dst: &mut [MaybeUninit<u8>], ) -> Result<usize, Error>
Get an item at the specified index and copy it into the provided destination buffer.
Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.
Note that if the destination buffer is not aligned to the original data type’s alignment, the caller should not transmute the decompressed data to original type, as this may lead to undefined behavior.
Sourcepub fn items(&self, idx: Range<usize>) -> Result<Vec<u8>, Error>
pub fn items(&self, idx: Range<usize>) -> Result<Vec<u8>, Error>
Get a range of items specified by the index range.
Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.
Note that the returned vector may not be aligned to the original data type’s alignment, and the caller should
ensure that the alignment is correct before transmuting it to original type. If the alignment does not match
the original data type, the bytes should be copied to a new aligned allocation before transmuting, otherwise
undefined behavior may occur. Alternatively, the caller can use Self::items_into and provide an already
aligned destination buffer.
Sourcepub fn items_into(
&self,
idx: Range<usize>,
dst: &mut [MaybeUninit<u8>],
) -> Result<usize, Error>
pub fn items_into( &self, idx: Range<usize>, dst: &mut [MaybeUninit<u8>], ) -> Result<usize, Error>
Get a range of items specified by the index range and copy them into the provided destination buffer.
Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.
Note that if the destination buffer is not aligned to the original data type’s alignment, the caller should not transmute the decompressed data to original type, as this may lead to undefined behavior.
Sourcepub fn shallow_clone(&self) -> Chunk<'_>
pub fn shallow_clone(&self) -> Chunk<'_>
Create a shallow clone of the chunk without re-allocating the internal buffer.