"""Generate the Blosc2 frames the `filters_blosc2` unit tests decode. Each case is `.b2f` (a Blosc2 contiguous frame, what the HDF5 Blosc2 filter stores per chunk) and `.out` (what decoding it must give: the first chunk of a plain frame, or the whole array in C order for a B2ND frame), or `.err` (a frame clawhdf5 must refuse; the file holds a word the error message must contain). These cover what files written by h5py + hdf5plugin never contain, but a Blosc2 frame may: special chunks (repeated value, NaN, uninitialised), the delta filter over many blocks and odd type sizes, bit shuffle of blocks that are not a multiple of 8 elements, shuffle with a byte-group size, forced stream splitting, multi-chunk B2ND arrays with padded edge chunks and a chunk of zeros, and features clawhdf5 refuses (dictionaries, registered filters). Written with python-blosc2 4.13.1 (c-blosc2 3.3.4) in a scratch venv (`pip install blosc2`). Re-run only to regenerate: python generate.py """ import os import sys import blosc2 import numpy as np out = sys.argv[1] def save(name, frame, expected): with open(os.path.join(out, name + ".b2f"), "wb") as f: f.write(frame) with open(os.path.join(out, name + ".out"), "wb") as f: f.write(expected) def save_err(name, frame, word): with open(os.path.join(out, name + ".b2f"), "wb") as f: f.write(frame) with open(os.path.join(out, name + ".err"), "w") as f: f.write(word) def plain(data, **cparams): """A one-chunk super-chunk frame of `data`, as hdf5-blosc2 writes.""" data = np.ascontiguousarray(data) cp = blosc2.CParams(typesize=data.dtype.itemsize, **cparams) sc = blosc2.SChunk(chunksize=data.nbytes, cparams=cp) sc.append_data(data) return sc.to_cframe(), data.tobytes() def special(nitems, dtype, kind, value=None): dt = np.dtype(dtype) sc = blosc2.SChunk(chunksize=nitems * dt.itemsize, cparams=blosc2.CParams(typesize=dt.itemsize)) sc.fill_special(nitems, kind, value) return sc.to_cframe() # Special chunks. A repeated value stays in the frame as a 33+ byte chunk; # NaN and uninitialised chunks become special offsets. save("value_i4", special(300, "