blosc2
Rust bindings for blosc2 - a fast, compressed, persistent binary data store library.
Provide a safe interface to the blosc2 library, which is a new major version of the original blosc library.
Getting Started
To use this library, add the following to your Cargo.toml:
[]
= "0.1"
In the following example we compress a vector of integers into a chunk of bytes and then decompress it back:
use ;
let data: = ;
let i32len = ;
let data_bytes =
unsafe ;
// Compress the data into a Chunk
let cparams = default
.typesize
.clevel
.nthreads
.clone;
let chunk: Chunk = new
.unwrap
.compress
.unwrap;
let chunk_bytes: & = chunk.as_bytes;
// Decompress the Chunk
let dparams = default;
let decompressed = new
.unwrap
.decompress
.unwrap;
// Check that the decompressed data matches the original
assert_eq!;
// A chunk support random access to individual items
assert_eq!;
assert_eq!;
assert_eq!;
Super Chunk
In addition to the basic Chunk, this library provides a SChunk (Super Chunk) that treat
multiple chunks as a single entity. A super chunk can be saved or loaded from or to files, and
it supports random access to chunks or individual items across all chunks.
use ;
let i32len = ;
let cparams = default
.typesize
.clone;
let mut schunk = new_in_memory.unwrap;
// Create two data arrays
let data1: = ;
let data2: = ;
let data1_bytes =
unsafe ;
let data2_bytes =
unsafe ;
// Append the first data array to the SChunk, which will be compressed using SChunk's CParams
schunk.append.unwrap;
assert_eq!;
assert_eq!;
// Append the second data array to the SChunk, as already compressed data
let data2_cparams = default
.typesize // typesize must match the SChunk's CParams
.clevel
.clone;
let data2_chunk = new
.unwrap
.compress
.unwrap;
schunk.append_chunk.unwrap;
assert_eq!;
assert_eq!;
// Random access a whole chunk within the super-chunk
assert_eq!;
// Random access individual items within the super-chunk
assert_eq!;
assert_eq!;
Features
Cargo features enable or disable support for various compression codecs such as zstd and
zlib.