|
libzarr
Header-only C++17 Zarr v2/v3, WASM-compatible
|
A small, dependency-light, header-only C++17 library for reading and writing the Zarr array storage format — v2 and v3.
Status: 1.0 (stable). Zarr v2 and v3 read/write including sharding are conformance-tested against zarr-python in both directions, as are STORED-entry ZIP archives. The public API is frozen and machine-checked (docs/API.md); the stability promise is docs/COMPATIBILITY.md.
The snippets below are abridged from examples/, where every example is a complete program compiled and run in CI. Agent-oriented recipes live in SKILL.md.
Create and write — v2 or v3, optionally sharded (from examples/quickstart.cpp and examples/custom_store.cpp):
Read an existing store — the format version is probed automatically, consolidated metadata is used when present:
ZIP archives — a whole store in one file, chunks still byte-range-readable (from examples/archive.cpp):
Custom backends — everything runs against the key→bytes zarr::Store interface; subclass it to serve bytes from HTTP, a database, a cache, or fetch() under WASM (from examples/custom_store.cpp).
Compression at work: examples/compression.cpp. Anything that goes wrong — malformed metadata, unknown codecs, out-of-range reads — throws zarr::error with a precise message.
include/ (plus the vendored third_party/) on your include path; no build system required to consume.LIBZARR_HAS_ZLIB, LIBZARR_HAS_BLOSC). A codec that is not built in fails with a clear error, never a missing symbol.Store interface you can back with memory, files, fetch, or HTTP range requests; the std::filesystem backend is a separate adapter header WASM builds simply omit. The Emscripten build is a required CI check.libzarr implements the Zarr v2 spec and the Zarr v3 core spec (v3.1) with its named codec specs, including sharding_indexed. What we read (accept) and write (emit) is documented feature-by-feature in docs/SPEC.md, each claim citing the test that proves it; architecture rationale lives in docs/DESIGN.md. Interoperability is checked against stores written by other implementations (zarr-python, TensorStore, GDAL, netCDF/NCZarr, omero-zarr) — validated locally against other implementations (TensorStore, GDAL, netCDF/NCZarr, omero-zarr) and live public stores — see tests/wild/.
Rendered API reference: **https://kharchenkolab.github.io/libzarr/** (Doxygen, built from the headers on every push). Task-oriented recipes are in SKILL.md. The complete public surface is enumerated in docs/API.md (machine-generated and CI-checked), and the stability guarantee is in docs/COMPATIBILITY.md.
Consuming the library needs none of this — it is header-only. Point your compiler at include/ (and third_party/ for the vendored JSON) and #include <libzarr/libzarr.hpp>. A single-file build is also available: tools/amalgamate.py produces zarr.hpp.
For CMake projects, add_subdirectory() or FetchContent expose the libzarr::libzarr target directly. An installed copy is consumed the standard way:
Enable optional codecs at configure time with -DLIBZARR_WITH_ZLIB=ON (also _BLOSC, _ZSTD); the installed package re-resolves those dependencies for consumers automatically.
Via vcpkg, use the overlay port shipped in this repo (codecs are features; CI installs and consumes it on every push):
MIT — see [LICENSE](LICENSE).