blosc-rs

Crates.ioblosc-rs
lib.rsblosc-rs
version0.4.0
created_at2025-06-27 20:58:44.373019+00
updated_at2025-07-18 13:54:16.38069+00
descriptionSafe Rust bindings for blosc - a blocking, shuffling and lossless compression library
homepage
repositoryhttps://github.com/barakugav/blosc-rs
max_upload_size
id1729321
size43,224
Barak Ugav (barakugav)

documentation

README

blosc-rs

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);
Commit count: 0

cargo fmt