Struct q_compress::wrapped::Compressor
source · pub struct Compressor<T: NumberLike>(_);
Expand description
Converts vectors of numbers into compressed bytes for use in a wrapping columnar data format.
All compressor methods leave its state unchanged if they return an error.
You can configure behavior like compression level by instantiating with
.from_config()
You can use the wrapped compressor at a data page level.
Implementations§
source§impl<T: NumberLike> Compressor<T>
impl<T: NumberLike> Compressor<T>
sourcepub fn from_config(config: CompressorConfig) -> Self
pub fn from_config(config: CompressorConfig) -> Self
Creates a new compressor, given a CompressorConfig
.
Internally, the compressor builds Flags
as well as an internal
configuration that doesn’t show up in the output file.
You can inspect the flags it chooses with .flags()
.
sourcepub fn header(&mut self) -> QCompressResult<()>
pub fn header(&mut self) -> QCompressResult<()>
Writes out a header using the compressor’s data type and flags. Will return an error if the compressor has already written the header.
Each .qco file must start with such a header, which contains:
- a 4-byte magic header for “qco!” in ascii,
- a byte for the data type (e.g.
i64
has byte 1 andf64
has byte 5), and - bytes for the flags used to compress.
sourcepub fn chunk_metadata(
&mut self,
nums: &[T],
spec: &ChunkSpec
) -> QCompressResult<ChunkMetadata<T>>
pub fn chunk_metadata( &mut self, nums: &[T], spec: &ChunkSpec ) -> QCompressResult<ChunkMetadata<T>>
Writes out and returns chunk metadata after training the compressor.
Will return an error if the compressor has not yet written the header,
in the middle of a chunk, or if the spec
provided is
incompatible with the count of nums
.
The spec
indicates how the chunk’s data pages will be broken up;
see ChunkSpec
for more detail.
After this method, the compressor retains some precomputed information that only gets freed after every data page in the chunk has been written.
sourcepub fn data_page(&mut self) -> QCompressResult<()>
pub fn data_page(&mut self) -> QCompressResult<()>
Writes out a data page, using precomputed data passed in through
.chunk_metadata
.
Will return an error if the compressor is not at the start of a data
page in the middle of a chunk.
sourcepub fn drain_bytes(&mut self) -> Vec<u8>
pub fn drain_bytes(&mut self) -> Vec<u8>
Returns all bytes produced by the compressor so far that have not yet been read.
Trait Implementations§
source§impl<T: Clone + NumberLike> Clone for Compressor<T>
impl<T: Clone + NumberLike> Clone for Compressor<T>
source§fn clone(&self) -> Compressor<T>
fn clone(&self) -> Compressor<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more