| Crates.io | zarrs_ffi |
| lib.rs | zarrs_ffi |
| version | 0.9.4 |
| created_at | 2024-03-10 00:17:33.292795+00 |
| updated_at | 2025-09-18 12:51:15.352859+00 |
| description | FFI bindings for the zarrs crate |
| homepage | |
| repository | https://github.com/zarrs/zarrs_ffi |
| max_upload_size | |
| id | 1168230 |
| size | 301,573 |
C/C++ bindings for the zarrs crate, a Rust library for the Zarr storage format for multidimensional arrays and metadata.
zarrs_ffi is a single header library: zarrs.h (docs).
Currently zarrs_ffi only supports a small subset of the zarrs API.
A changelog can be found here.
#include "zarrs.h"
void main() {
// Open a filesystem store pointing to a zarr hierarchy
ZarrsStorage storage = nullptr;
zarrs_assert(zarrsCreateStorageFilesystem("/path/to/hierarchy.zarr", &storage));
// Open an array in the hierarchy
ZarrsArray array = nullptr;
zarrs_assert(zarrsOpenArrayRW(storage, "/array", &array));
// Get the array dimensionality
size_t dimensionality;
zarrs_assert(zarrsArrayGetDimensionality(array, &dimensionality));
assert(dimensionality == 2);
// Retrieve the decoded bytes of the chunk at [0, 0]
size_t indices[] = {0, 0};
size_t chunk_size;
zarrs_assert(zarrsArrayGetChunkSize(array, 2, indices, &chunk_size));
std::unique_ptr<uint8_t[]> chunk_bytes(new uint8_t[chunk_size]);
zarrs_assert(zarrsArrayRetrieveChunk(array, 2, indices, chunk_size, chunk_bytes.get()));
}
See a more comprehensive example in the examples directory.
CMAKE_MODULE_PATHfind_package(zarrs <version> REQUIRED COMPONENTS zarrs/bz2)
<version> with the latest release: 0.9 or 0.9.4)zarrs is retrieved from GitHub using FetchContent and built using corrosionzarrs codecszarrs_ffi library is available as the zarrs::zarrs or zarrs::zarrs-static targetA complete CMake example can be found in examples/.
Building generates a header, and a platform-dependent static and dynamic library.
cargo build --release --features cbindgen # -> zarrs.h and target/release/[lib]zarrs_ffi{.a,.so,.dll,.dylib}
zarrs.h is only re-generated if the cbindgen feature is enabled.
Encoding and decoding performance may be improved with avx2/sse2 enabled (if supported).
Compile with either of:
RUSTFLAGS="-C target-cpu=native"RUSTFLAGS="-C target-feature=+avx2,+sse2"Non-default zarrs codecs (see zarrs crate features) can be enabled with the all_codecs feature.
Alternatively, individual codecs can be enabled by passing them as feature flags.
For example:
cargo build --release --features cbindgen --features zarrs/zstd,zarrs/bitround,zarrs/zfp,zarrs/bz2,zarrs/pcodec,zarrs/gdeflate
zarrs_ffi is licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.