#lossless-compression #bindings

sys blosc-rs

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

6 releases (3 breaking)

0.4.0 Jul 18, 2025
0.3.1 Jul 4, 2025
0.2.0 Jul 2, 2025
0.1.2 Jul 1, 2025
0.1.0 Jun 27, 2025

#1026 in Compression

Download history

458 downloads per month

Apache-2.0

42KB
578 lines

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);

Dependencies

~0–2.2MB
~42K SLoC