Crate blosc_rs

Source
Expand description

Rust bindings for blosc - a blocking, shuffling and lossless compression library.

Provide a safe interface to the blosc library. The crate has zero runtime dependencies.

§Getting Started

To use this library, add the following to your Cargo.toml:

[dependencies]
blosc-rs = "0.4"

# Or alternatively, rename the crate to `blosc`
blosc = { package = "blosc-rs", version = "0.4" }

In the following example we compress a vector of integers and then decompress it back:

use blosc_rs::{CompressAlgo, Encoder, Decoder};

let data: [i32; 7] = [1, 2, 3, 4, 5, 6, 7];

let data_bytes = unsafe {
    std::slice::from_raw_parts(
        data.as_ptr() as *const u8,
        data.len() * std::mem::size_of::<i32>(),
    )
};
let numinternalthreads = 4;

let compressed = Encoder::default()
    .typesize(std::mem::size_of::<i32>().try_into().unwrap())
    .numinternalthreads(numinternalthreads)
    .compress(&data_bytes)
    .expect("failed to compress");

let decoder = Decoder::new(&compressed).expect("invalid buffer");

// Read some items using random access, without decompressing the entire buffer
assert_eq!(&data_bytes[0..4], decoder.item(0).expect("failed to get the 0-th item"));
assert_eq!(&data_bytes[12..16], decoder.item(3).expect("failed to get the 3-th item"));
assert_eq!(&data_bytes[4..20], decoder.items(1..5).expect("failed to get items 1 to 4"));

// Decompress the entire buffer
let decompressed = decoder.decompress(numinternalthreads).expect("failed to decompress");
assert_eq!(data_bytes, decompressed);

§Features

Cargo features enable or disable support for various compression codecs such as zstd, lz4 and zlib. The blosclz codec is always supported.

Structs§

Decoder
A decoder for Blosc compressed data.
Encoder
Encoder for Blosc compression.
Level
A compression level used by Blosc.

Enums§

CompressAlgo
Represents the compression algorithms supported by Blosc.
CompressError
Error that can occur during compression.
DecompressError
Error that can occur during decompression.
Shuffle
Represents the shuffle filters used by Blosc.

Constants§

BLOSC_C_VERSION
The version of the underlying C-blosc library used by this crate.
VERSION
The version of the crate.