3#ifndef LIBZARR_CODECS_BLOSC_HPP
4#define LIBZARR_CODECS_BLOSC_HPP
6#ifndef LIBZARR_HAS_BLOSC
7#error "libzarr/codecs_blosc.hpp requires c-blosc: define LIBZARR_HAS_BLOSC and link blosc"
17#include "libzarr/detail/common.hpp"
24namespace zarr::detail {
27 std::string cname =
"lz4";
30 std::size_t typesize = 1;
31 std::size_t blocksize = 0;
34inline Bytes blosc_decompress_bytes(
const Bytes& src, std::optional<std::uint64_t> expected,
36 std::size_t nbytes = 0;
37 if (blosc_cbuffer_validate(src.data(), src.size(), &nbytes) < 0) {
38 throw error(std::string(what) +
": corrupt blosc frame");
40 if (expected && nbytes != *expected) {
41 throw error(std::string(what) +
": blosc frame decodes to " + std::to_string(nbytes) +
42 " bytes, expected " + std::to_string(*expected));
45 const int n = blosc_decompress_ctx(src.data(), out.data(), out.size(), 1);
46 if (n < 0 ||
static_cast<std::size_t
>(n) != nbytes) {
47 throw error(std::string(what) +
": blosc decompression failed (" + std::to_string(n) +
")");
52inline Bytes blosc_compress_bytes(
const Bytes& src,
const BloscParams& params,
const char* what) {
53 Bytes out(src.size() + BLOSC_MAX_OVERHEAD);
54 const int n = blosc_compress_ctx(params.clevel, params.shuffle, params.typesize, src.size(),
55 src.data(), out.data(), out.size(), params.cname.c_str(),
58 throw error(std::string(what) +
": blosc compression failed (" + std::to_string(n) +
")");
60 out.resize(
static_cast<std::size_t
>(n));
CodecSpec shuffle(int elementsize=0)
shuffle: byte-transposition filter. elementsize 0 means the dtype size.
Definition metadata.hpp:69
std::vector< std::uint8_t > Bytes
Owned byte buffer used throughout the value-based public API.
Definition types.hpp:42