pub struct Compressor<T> where
    T: NumberLike
{ /* private fields */ }
Expand description

Converts vectors of numbers into compressed bytes.

You can use the compressor very easily:

use q_compress::Compressor;

let my_nums = vec![1, 2, 3];
let compressor = Compressor::<i32>::default();
let bytes = compressor.simple_compress(&my_nums);

You can also get full control over the compression process:

use q_compress::{BitWriter, Compressor, CompressorConfig};

let compressor = Compressor::<i32>::from_config(CompressorConfig {
  compression_level: 5,
  ..Default::default()
});
let mut writer = BitWriter::default();

compressor.header(&mut writer).expect("header failure");
let chunk_0 = vec![1, 2, 3];
compressor.chunk(&chunk_0, &mut writer).expect("chunk failure");
let chunk_1 = vec![4, 5];
compressor.chunk(&chunk_1, &mut writer).expect("chunk failure");
compressor.footer(&mut writer).expect("footer failure");

let bytes = writer.pop();

Note that in practice we would need larger chunks than this to achieve good compression, preferably containing 10k-10M numbers.

Implementations

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().

Returns a reference to the compressor’s flags.

Writes out a header using the compressor’s data type and flags. Will return an error if the writer is not at a byte-aligned position.

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 and f64 has byte 5), and
  • bytes for the flags used to compress.

Writes out a chunk of data representing the provided numbers. Will return an error if the writer is not at a byte-aligned position or the slice of numbers is empty.

Each chunk contains a ChunkMetadata section followed by the chunk body. The chunk body encodes the numbers passed in here.

Writes out a single footer byte indicating that the .qco file has ended. Will return an error if the writer is not byte-aligned.

Takes in a slice of numbers and returns compressed bytes.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.