Super-chunk#

This API describes the new Blosc 2 container, the super-chunk (or schunk for short).

struct blosc2_storage#

This struct is meant for holding storage parameters for a for a blosc2 container, allowing to specify, for example, how to interpret the contents included in the schunk.

Public Members

bool contiguous#

Whether the chunks are contiguous or sparse.

char *urlpath#

The path for persistent storage. If NULL, that means in-memory.

blosc2_cparams *cparams#

The compression params when creating a schunk. If NULL, sensible defaults are used depending on the context.

blosc2_dparams *dparams#

The decompression params when creating a schunk. If NULL, sensible defaults are used depending on the context.

blosc2_io *io#

Input/output backend.

struct blosc2_schunk#

This struct is the standard container for Blosc 2 compressed data.

This is essentially a container for Blosc 1 chunks of compressed data, and it allows to overcome the 32-bit limitation in Blosc 1. Optionally, a blosc2_frame can be attached so as to store the compressed chunks contiguously.

Public Members

uint8_t compcode#

The default compressor. Each chunk can override this.

uint8_t compcode_meta#

The default compressor metadata. Each chunk can override this.

uint8_t clevel#

The compression level and other compress params.

uint8_t splitmode#

The split mode.

int32_t typesize#

The type size.

int32_t blocksize#

The requested size of the compressed blocks (0; meaning automatic).

int32_t chunksize#

Size of each chunk. 0 if not a fixed chunksize.

uint8_t flags2#

Secondary chunk-format flags shared by all chunks in the schunk. 0 when empty.

uint8_t use_dict#

Whether to use a dictionary for codec compression (1) or not (0).

uint8_t filters[BLOSC2_MAX_FILTERS]#

The (sequence of) filters. 8-bit per filter.

uint8_t filters_meta[BLOSC2_MAX_FILTERS]#

Metadata for filters. 8-bit per meta-slot.

int64_t nchunks#

Number of chunks in super-chunk.

int64_t current_nchunk#

The current chunk that is being accessed.

int64_t nbytes#

The data size (uncompressed).

int64_t cbytes#

The data size + chunks header size (compressed).

uint8_t **data#

Pointer to chunk data pointers buffer.

size_t data_len#

Length of the chunk data pointers buffer.

blosc2_storage *storage#

Pointer to storage info.

blosc2_frame *frame#

Pointer to frame used as store for chunks. uint8_t* ctx; Context for the thread holder. NULL if not acquired.

blosc2_context *cctx#

Context for compression.

blosc2_context *dctx#

Context for decompression.

struct blosc2_metalayer *metalayers[16]#

The array of metalayers.

uint16_t nmetalayers#

The number of metalayers in the super-chunk.

int16_t nvlmetalayers#

The number of variable-length metalayers.

void *tuner_params#

Tune configuration.

int64_t change_tick#

Bumped whenever the (vl)metalayers change: by local mutations and by the refresh that follows a mutation made through another handle on the same on-disk frame. Upper layers compare it against a cached value to know whether their deserialized view of the metalayers is still current.

blosc2_schunk *blosc2_schunk_new(blosc2_storage *storage)#

Create a new super-chunk.

Remark

In case that storage.urlpath is not NULL, the data is stored on-disk. If the data file(s) exist, they are overwritten.

Parameters:
  • storage – The storage properties.

Returns:

The new super-chunk.

int blosc2_schunk_free(blosc2_schunk *schunk)#

Release resources from a super-chunk.

Remark

All the memory resources attached to the super-chunk are freed. If the super-chunk is on-disk, the data continues there for a later re-opening.

Parameters:
  • schunk – The super-chunk to be freed.

Returns:

0 if success.

blosc2_schunk *blosc2_schunk_open(const char *urlpath)#

Open an existing super-chunk that is on-disk (frame).

No in-memory copy is made.

Parameters:
  • urlpath – The file name.

Returns:

The new super-chunk. NULL if not found or not in frame format.

blosc2_schunk *blosc2_schunk_open_offset(const char *urlpath, int64_t offset)#

Open an existing super-chunk that is on-disk (frame).

No in-memory copy is made.

Parameters:
  • urlpath – The file name.

  • offset – The frame offset.

Returns:

The new super-chunk. NULL if not found or not in frame format.

blosc2_schunk *blosc2_schunk_open_udio(const char *urlpath, const blosc2_io *udio)#

Open an existing super-chunk (no copy is made) using a user-defined I/O interface.

Parameters:
  • urlpath – The file name.

  • udio – The user-defined I/O interface.

Returns:

The new super-chunk.

blosc2_schunk *blosc2_schunk_open_offset_udio(const char *urlpath, int64_t offset, const blosc2_io *udio)#

Open an existing super-chunk (no copy is made) using a user-defined I/O interface.

Parameters:
  • urlpath – The file name.

  • offset – The frame offset.

  • udio – The user-defined I/O interface.

Returns:

The new super-chunk.

blosc2_schunk *blosc2_schunk_copy(blosc2_schunk *schunk, blosc2_storage *storage)#

Create a copy of a super-chunk.

Remark

If schunk has a postfilter, the copy holds the data as read from schunk, i.e. the output of the postfilter (except with variable-length blocks, whose chunks are always copied as they are). The copy does not inherit the postfilter: it reads that output as it is, unless storage sets a postfilter in its dparams, which then runs on it again. To serialize the chunks as they are stored instead, see blosc2_schunk_to_buffer().

Parameters:
  • schunk – The super-chunk to be copied.

  • storage – The storage properties.

Returns:

The new super-chunk.

blosc2_schunk *blosc2_schunk_from_buffer(uint8_t *cframe, int64_t len, bool copy)#

Create a super-chunk out of a contiguous frame buffer.

Remark

If copy is false, the cframe buffer passed will be owned by the super-chunk and will be automatically freed when blosc2_schunk_free() is called. If the user frees it after the opening, bad things will happen. Don’t do that (or set copy).

Parameters:
  • cframe – The buffer of the in-memory frame.

  • copy – Whether the super-chunk should make a copy of the cframe data or not. The copy will be made to an internal sparse frame.

  • len – The length of the buffer (in bytes).

Returns:

The new super-chunk.

int64_t blosc2_schunk_to_buffer(blosc2_schunk *schunk, uint8_t **cframe, bool *needs_free)#

Convert a super-chunk into a contiguous frame buffer.

Remark

The frame holds the chunks as they are stored, whatever the storage of schunk: a postfilter of schunk is not applied (unlike in blosc2_schunk_copy()), and it is not part of the frame either, so a super-chunk made from the frame reads the stored values until the same postfilter is set on it again. For a frame with the postfiltered values, serialize a blosc2_schunk_copy() of schunk. The same holds for blosc2_schunk_to_buffer_alloc(), blosc2_schunk_to_file() and blosc2_schunk_append_file().

Parameters:
  • schunk – The super-chunk to convert.

  • cframe – The address of the destination buffer (output).

  • needs_free – The pointer to a boolean indicating if it is the user’s responsibility to free the resulting cframe buffer or not.

Returns:

If successful, return the size of the (frame) cframe buffer. Else, a negative value.

int64_t blosc2_schunk_to_buffer_alloc(blosc2_schunk *schunk, uint8_t *(*alloc)(int64_t len, void *user_data), void *user_data)#

Convert a super-chunk into a contiguous frame in a buffer provided by the caller.

The frame is the same that blosc2_schunk_to_buffer() returns, but it goes into memory that the caller owns, e.g. the final destination of the serialized super-chunk, which saves copying it there afterwards. Unless the super-chunk already is a frame in memory, the frame is moreover written in place instead of being built first.

Remark

Like blosc2_schunk_to_buffer(), it writes the chunks as they are stored, without applying a postfilter of schunk.

Parameters:
  • schunk – The super-chunk to convert.

  • alloc – Called once with the exact length of the frame; it returns a buffer of (at least) that many bytes, or NULL to give up.

  • user_data – Passed on to alloc.

Returns:

If successful, return the size of the frame written into the buffer. Else (also when alloc returns NULL), a negative value.

int64_t blosc2_schunk_to_file(blosc2_schunk *schunk, const char *urlpath)#

Store a super-chunk into a file.

Remark

The file holds the same frame that blosc2_schunk_to_buffer() returns: the chunks as they are stored, without applying a postfilter of schunk.

Parameters:
  • schunk – The super-chunk to write.

  • urlpath – The path for persistent storage.

Returns:

If successful, return the size of the (fileframe) in urlpath. Else, a negative value.

int64_t blosc2_schunk_append_file(blosc2_schunk *schunk, const char *urlpath)#

Append a super-chunk into a file.

Remark

It appends the same frame that blosc2_schunk_to_buffer() returns: the chunks as they are stored, without applying a postfilter of schunk.

Parameters:
  • schunk – The super-chunk to write.

  • urlpath – The path for persistent storage.

Returns:

If successful, return the offset where schunk has been appended in urlpath. Else, a negative value.

int blosc2_schunk_get_cparams(blosc2_schunk *schunk, blosc2_cparams **cparams)#

Return the cparams associated to a super-chunk.

Parameters:
  • schunk – The super-chunk from where to extract the compression parameters.

  • cparams – The pointer where the compression params will be returned.

Returns:

0 if succeeds. Else a negative code is returned.

Warning

A new struct is allocated, and the user should free it after use.

int blosc2_schunk_get_dparams(blosc2_schunk *schunk, blosc2_dparams **dparams)#

Return the dparams struct associated to a super-chunk.

Parameters:
  • schunk – The super-chunk from where to extract the decompression parameters.

  • dparams – The pointer where the decompression params will be returned.

Returns:

0 if succeeds. Else a negative code is returned.

Warning

A new struct is allocated, and the user should free it after use.

int blosc2_schunk_reorder_offsets(blosc2_schunk *schunk, int64_t *offsets_order)#

Reorder the chunk offsets of an existing super-chunk.

Parameters:
  • schunk – The super-chunk whose chunk offsets are to be reordered.

  • offsets_order – The new order of the chunk offsets.

Returns:

0 if succeeds. Else a negative code is returned.

int64_t blosc2_schunk_frame_len(blosc2_schunk *schunk)#

Get the length (in bytes) of the internal frame of the super-chunk.

Parameters:
  • schunk – The super-chunk.

Returns:

The length (in bytes) of the internal frame. If there is not an internal frame, an estimate of the length is provided.

int64_t blosc2_schunk_fill_special(blosc2_schunk *schunk, int64_t nitems, int special_value, int32_t chunksize)#

Quickly fill an empty frame with special values (zeros, NaNs, uninit).

Parameters:
  • schunk – The super-chunk to be filled. This must be empty initially.

  • nitems – The number of items to fill.

  • special_value – The special value to use for filling. The only values supported for now are BLOSC2_SPECIAL_ZERO, BLOSC2_SPECIAL_NAN and BLOSC2_SPECIAL_UNINIT.

  • chunksize – The chunksize for the chunks that are to be added to the super-chunk.

Returns:

The total number of chunks that have been added to the super-chunk. If there is an error, a negative value is returned.

int64_t blosc2_schunk_append_buffer(blosc2_schunk *schunk, const void *src, int32_t nbytes)#

Append a src data buffer to a super-chunk.

Parameters:
  • schunk – The super-chunk where data will be appended.

  • src – The buffer of data to compress.

  • nbytes – The size of the src buffer.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

int64_t blosc2_schunk_insert_buffer(blosc2_schunk *schunk, int64_t nchunk, const void *src, int32_t nbytes)#

Compress a src data buffer and insert it as a new chunk at a specific position in a super-chunk.

Same as compressing src with the super-chunk’s context and inserting the result with blosc2_schunk_insert_chunk(), but frames are written from a compression buffer that the calling thread reuses, not a new one per chunk.

Parameters:
  • schunk – The super-chunk where the chunk will be inserted.

  • nchunk – The position where the chunk will be inserted.

  • src – The buffer of data to compress.

  • nbytes – The size of the src buffer.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

int64_t blosc2_schunk_update_buffer(blosc2_schunk *schunk, int64_t nchunk, const void *src, int32_t nbytes)#

Compress a src data buffer and replace the chunk at a specific position in a super-chunk with it.

Same as compressing src with the super-chunk’s context and storing the result with blosc2_schunk_update_chunk(), but frames are written from a compression buffer that the calling thread reuses, not a new one per chunk.

Parameters:
  • schunk – The super-chunk where the chunk will be updated.

  • nchunk – The position of the chunk to update.

  • src – The buffer of data to compress.

  • nbytes – The size of the src buffer.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

int blosc2_schunk_get_slice_buffer(blosc2_schunk *schunk, int64_t start, int64_t stop, void *buffer)#

Fill buffer with a schunk slice.

Parameters:
  • schunk – The super-chunk from where to extract a slice.

  • start – Index (0-based) where the slice begins.

  • stop – The first index (0-based) that is not in the selected slice.

  • buffer – The buffer where the data will be stored.

Returns:

An error code.

Warning

You must make sure that you have enough space in buffer to store the uncompressed data.

int blosc2_schunk_get_sparse_buffer(blosc2_schunk *schunk, int64_t ncoords, const int64_t *coords, void *buffer)#

Fill buffer with elements at the given coordinates from a schunk.

Parameters:
  • schunk – The super-chunk from where to extract elements.

  • ncoords – The number of coordinates.

  • coords – The coordinates of the elements to be extracted.

  • buffer – The buffer where the data will be stored.

Returns:

An error code.

Warning

You must make sure that you have enough space in buffer to store the uncompressed data.

int blosc2_schunk_set_slice_buffer(blosc2_schunk *schunk, int64_t start, int64_t stop, void *buffer)#

Update a schunk slice from buffer.

Parameters:
  • schunk – The super-chunk where to set the slice.

  • start – Index (0-based) where the slice begins.

  • stop – The first index (0-based) that is not in the selected slice.

  • buffer – The buffer containing the data to set.

Returns:

An error code.

void blosc2_schunk_avoid_cframe_free(blosc2_schunk *schunk, bool avoid_cframe_free)#

Set the private avoid_cframe_free field in a frame.

Parameters:
  • schunk – The super-chunk referencing the frame.

  • avoid_cframe_free – The value to set in the blosc2_frame_s structure.

Warning

If you set it to true you will be responsible of freeing it.

blosc2_storage blosc2_get_blosc2_storage_defaults(void)#

Get default struct for blosc2_storage meant for user initialization.

blosc2_io blosc2_get_blosc2_io_defaults(void)#

Get default struct for blosc2_io meant for user initialization.

blosc2_stdio_mmap blosc2_get_blosc2_stdio_mmap_defaults(void)#

Get default struct for blosc2_stdio_mmap meant for user initialization.

Dealing with chunks#

int blosc2_schunk_get_chunk(blosc2_schunk *schunk, int64_t nchunk, uint8_t **chunk, bool *needs_free)#

Return a compressed chunk that is part of a super-chunk in the chunk parameter.

Parameters:
  • schunk – The super-chunk from where to extract a chunk.

  • nchunk – The chunk to be extracted (0 indexed).

  • chunk – The pointer to the chunk of compressed data.

  • needs_free – The pointer to a boolean indicating if it is the user’s responsibility to free the chunk returned or not.

Returns:

The size of the (compressed) chunk or 0 if it is non-initialized. If some problem is detected, a negative code is returned instead.

Note

If the frame on disk has been modified through another handle (or process), the handle re-syncs its view automatically on the next access. A concurrent (non-serialized) write can still surface as BLOSC2_ERROR_FILE_READ; retry or reopen the super-chunk in that case. Writers must be serialized externally.

Warning

If the super-chunk is backed by a frame that is disk-based, a buffer is allocated for the (compressed) chunk, and hence a free is needed. You can check whether the chunk requires a free with the needs_free parameter. If the chunk does not need a free, it means that a pointer to the location in the super-chunk (or the backing in-memory frame) is returned in the chunk parameter.

int blosc2_schunk_get_lazychunk(blosc2_schunk *schunk, int64_t nchunk, uint8_t **chunk, bool *needs_free)#

Return a (lazy) compressed chunk that is part of a super-chunk in the chunk parameter.

Parameters:
  • schunk – The super-chunk from where to extract a chunk.

  • nchunk – The chunk to be extracted (0 indexed).

  • chunk – The pointer to the (lazy) chunk of compressed data.

  • needs_free – The pointer to a boolean indicating if it is the user’s responsibility to free the chunk returned or not.

Returns:

The size of the returned chunk buffer, or 0 if it is non-initialized. If some problem is detected, a negative code is returned instead. For regular chunks this matches the compressed chunk size. Note that a lazy chunk is somewhat larger than a regular chunk because of the trailer section (for details see README_CHUNK_FORMAT.rst).

Note

For disk-based frames, a lazy chunk is always returned.

Note

The return value is the effective size of the returned buffer. For lazy chunks, use this return value as srcsize when calling blosc2_decompress_ctx or blosc2_getitem_ctx. This value can be larger than the cbytes reported by blosc2_cbuffer_sizes because lazy chunks carry extra trailer metadata.

Note

If the frame on disk has been modified through another handle (or process), the handle re-syncs its view automatically on the next access. A concurrent (non-serialized) write can still surface as BLOSC2_ERROR_FILE_READ; retry or reopen the super-chunk in that case. Writers must be serialized externally.

Warning

Currently, a lazy chunk can only be used by blosc2_decompress_ctx and blosc2_getitem_ctx.

Warning

If the super-chunk is backed by a frame that is disk-based, a buffer is allocated for the (compressed) chunk, and hence a free is needed. You can check whether requires a free with the needs_free parameter. If the chunk does not need a free, it means that a pointer to the location in the super-chunk (or the backing in-memory frame) is returned in the chunk parameter. In this case the returned chunk is not lazy.

int blosc2_schunk_get_chunk_range(blosc2_schunk *schunk, int64_t nchunk, int64_t *offset, int64_t *nbytes)#

Where a chunk of a super-chunk stored in a contiguous frame on disk is in its file.

This lets callers read (or ask the operating system to read ahead) the bytes of the chunks they will need, e.g. in parallel, without reading any chunk to find them: the answer comes from the frame header and the chunk index, which opening the frame has read already (and which stay in the page cache).

Parameters:
  • schunk – The super-chunk.

  • nchunk – The chunk.

  • offset – Position of its first byte in the file.

  • nbytes – Its size in the file: the distance to the next chunk, which is the compressed size for chunks written in order and otherwise at most the largest possible chunk size. 0 for chunks that the index codes as a special value (zeros, NaNs, uninitialized), which have no bytes in the file.

Returns:

0 on success, or a negative error code (e.g. for super-chunks in memory or in sparse frames).

int blosc2_schunk_get_vlblock(blosc2_schunk *schunk, int64_t nchunk, int32_t nblock, uint8_t **dest, int32_t *destsize)#

Decompress a single variable-length block from a schunk chunk.

Convenience wrapper around blosc2_vldecompress_block_ctx that fetches the compressed chunk from schunk and decompresses only the requested VL block. Only the requested block is allocated and decompressed; all other blocks in the chunk are untouched.

Parameters:
  • schunk – The super-chunk from which to read.

  • nchunk – Zero-based index of the chunk inside the super-chunk.

  • nblock – Zero-based index of the VL block inside the chunk.

  • dest – On success, points to a newly allocated buffer containing the decompressed block. The caller is responsible for freeing it with free().

  • destsize – On success, the uncompressed byte size of the block.

Returns:

The uncompressed byte size of the block on success, or a negative error code. Returns BLOSC2_ERROR_INVALID_PARAM if the chunk does not use VL blocks or if nblock is out of range.

int blosc2_schunk_decompress_chunk(blosc2_schunk *schunk, int64_t nchunk, void *dest, int32_t nbytes)#

Decompress and return the nchunk chunk of a super-chunk.

If the chunk is uncompressed successfully, it is put in the *dest pointer.

Parameters:
  • schunk – The super-chunk from where the chunk will be decompressed.

  • nchunk – The chunk to be decompressed (0 indexed).

  • dest – The buffer where the decompressed data will be put.

  • nbytes – The size of the area pointed by *dest.

Returns:

The size of the decompressed chunk or 0 if it is non-initialized. If some problem is detected, a negative code is returned instead.

Warning

You must make sure that you have enough space to store the uncompressed data.

int64_t blosc2_schunk_append_chunk(blosc2_schunk *schunk, uint8_t *chunk, bool copy)#

Append an existing chunk to a super-chunk.

Parameters:
  • schunk – The super-chunk where the chunk will be appended.

  • chunk – The chunk to append. If copy is true, an internal copy is made, so chunk can be reused or freed if desired. If copy is false, ownership is transferred to the super-chunk on success; on error, the caller retains ownership.

  • copy – Whether the chunk should be copied internally or can be used as-is.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

int64_t blosc2_schunk_insert_chunk(blosc2_schunk *schunk, int64_t nchunk, uint8_t *chunk, bool copy)#

Insert a chunk at a specific position in a super-chunk.

Parameters:
  • schunk – The super-chunk where the chunk will be inserted.

  • nchunk – The position where the chunk will be inserted.

  • chunk – The chunk to insert. If copy is true, an internal copy is made, so chunk can be reused or freed if desired. If copy is false, ownership is transferred to the super-chunk on success; on error, the caller retains ownership.

  • copy – Whether the chunk should be copied internally or can be used as-is.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

int64_t blosc2_schunk_update_chunk(blosc2_schunk *schunk, int64_t nchunk, uint8_t *chunk, bool copy)#

Update a chunk at a specific position in a super-chunk.

Parameters:
  • schunk – The super-chunk where the chunk will be updated.

  • nchunk – The position where the chunk will be updated.

  • chunk – The new chunk. If copy is true, an internal copy is made, so chunk can be reused or freed if desired. If copy is false, ownership is transferred to the super-chunk on success; on error, the caller retains ownership.

  • copy – Whether the chunk should be copied internally or can be used as-is.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

int64_t blosc2_schunk_delete_chunk(blosc2_schunk *schunk, int64_t nchunk)#

Delete a chunk at a specific position in a super-chunk.

Parameters:
  • schunk – The super-chunk where the chunk will be deleted.

  • nchunk – The position where the chunk will be deleted.

Returns:

The number of chunks in super-chunk. If some problem is detected, this number will be negative.

Creating chunks#

int blosc2_chunk_zeros(blosc2_cparams cparams, int32_t nbytes, void *dest, int32_t destsize)#

Create a chunk made of zeros.

Parameters:
  • cparams – The compression parameters.

  • nbytes – The size (in bytes) of the chunk.

  • dest – The buffer where the data chunk will be put.

  • destsize – The size (in bytes) of the dest buffer; must be BLOSC_EXTENDED_HEADER_LENGTH at least.

Returns:

The number of bytes compressed (BLOSC_EXTENDED_HEADER_LENGTH). If negative, there has been an error and dest is unusable.

int blosc2_chunk_nans(blosc2_cparams cparams, int32_t nbytes, void *dest, int32_t destsize)#

Create a chunk made of nans.

Parameters:
  • cparams – The compression parameters; only 4 bytes (float) and 8 bytes (double) are supported.

  • nbytes – The size (in bytes) of the chunk.

  • dest – The buffer where the data chunk will be put.

  • destsize – The size (in bytes) of the dest buffer; must be BLOSC_EXTENDED_HEADER_LENGTH at least.

Returns:

The number of bytes compressed (BLOSC_EXTENDED_HEADER_LENGTH). If negative, there has been an error and dest is unusable.

Note

Whether the NaNs are floats or doubles will be given by the typesize.

int blosc2_chunk_repeatval(blosc2_cparams cparams, int32_t nbytes, void *dest, int32_t destsize, const void *repeatval)#

Create a chunk made of repeated values.

Parameters:
  • cparams – The compression parameters.

  • nbytes – The size (in bytes) of the chunk.

  • dest – The buffer where the data chunk will be put.

  • destsize – The size (in bytes) of the dest buffer.

  • repeatval – A pointer to the repeated value (little endian). The size of the value is given by cparams.typesize param.

Returns:

The number of bytes compressed (BLOSC_EXTENDED_HEADER_LENGTH + typesize). If negative, there has been an error and dest is unusable.

int blosc2_chunk_uninit(blosc2_cparams cparams, int32_t nbytes, void *dest, int32_t destsize)#

Create a chunk made of uninitialized values.

Parameters:
  • cparams – The compression parameters.

  • nbytes – The size (in bytes) of the chunk.

  • dest – The buffer where the data chunk will be put.

  • destsize – The size (in bytes) of the dest buffer; must be BLOSC_EXTENDED_HEADER_LENGTH at least.

Returns:

The number of bytes compressed (BLOSC_EXTENDED_HEADER_LENGTH). If negative, there has been an error and dest is unusable.

Frame specific functions#

int64_t *blosc2_frame_get_offsets(blosc2_schunk *schunk)#

Get the offsets of a frame in a super-chunk.

Parameters:
  • schunk – The super-chunk containing the frame.

Returns:

If successful, return a pointer to a buffer of the decompressed offsets. The number of offsets is equal to schunk->nchunks; the user is responsible to free this buffer. Else, return a NULL value.

Batch updates#

int blosc2_schunk_begin_updates(blosc2_schunk *schunk)#

Start a sequence of chunk updates of a super-chunk.

A contiguous frame keeps its chunks back to back, so an update that changes the compressed size of a chunk moves everything stored behind it: updating all n chunks one by one moves ~n^2/2 chunks. Between blosc2_schunk_begin_updates() and blosc2_schunk_end_updates(), such an update moves nothing else. The chunk goes into its old place when it fits there (together with the free space right before and after it), else to the end of the frame, and the space left over stays free until blosc2_schunk_end_updates() closes all of it in one pass, in which every chunk moves at most once. The frame is valid at every point in between, just larger, and cbytes includes the free space until the end.

Writing functions that update several chunks (b2nd_set_slice_cbuffer(), b2nd_set_orthogonal_selection(), b2nd_resize(), blosc2_schunk_set_slice_buffer()) do this by themselves; use it to bracket a sequence of such calls or of blosc2_schunk_update_chunk() calls.

It also takes the exclusive frame lock, as blosc2_schunk_lock() does, until blosc2_schunk_end_updates(). Brackets nest. For super-chunks that are not contiguous frames this is just the lock (a no-op without locking). A frame whose bracket is never closed stays valid; its free space just stays, like the space of deleted chunks.

Parameters:
  • schunk – The super-chunk.

Returns:

0 on success; a negative error code otherwise (then nothing has started).

int blosc2_schunk_end_updates(blosc2_schunk *schunk)#

End a sequence of chunk updates started with blosc2_schunk_begin_updates().

The outermost call closes the free space that the updates left in a contiguous frame (moving each chunk at most once; a frame on disk is cut to its new length) and releases the lock.

Parameters:
  • schunk – The super-chunk.

Returns:

0 on success; a negative error code otherwise. The lock is released either way.

Locking#

int blosc2_schunk_lock(blosc2_schunk *schunk)#

Take the exclusive frame lock of a super-chunk and hold it across several operations.

When the (opt-in) file locking is enabled on the handle (see the locking member of blosc2_stdio_params, or the BLOSC_LOCKING environment variable), every schunk operation locks and unlocks the on-disk frame individually, so a sequence of operations is not atomic as a whole. Bracketing the sequence between blosc2_schunk_lock() and blosc2_schunk_unlock() makes it atomic against other handles and processes: the operations inside nest on the already-held lock instead of re-acquiring it.

Everything inside the bracket is serialized exclusively — including plain reads through other locked handles — so keep brackets short. The bracket is re-entrant on the same handle. When locking is not enabled on the handle (or the super-chunk is not disk-based), this is a no-op returning success, so callers do not need to check whether locking is active.

Parameters:
  • schunk – The super-chunk.

Returns:

0 on success; a negative error code (e.g. BLOSC2_ERROR_LOCK) otherwise.

int blosc2_schunk_unlock(blosc2_schunk *schunk)#

Release the frame lock taken with blosc2_schunk_lock().

Parameters:
  • schunk – The super-chunk.

Returns:

0 on success; a negative error code otherwise. Like blosc2_schunk_lock(), a no-op when locking is not enabled.

int blosc2_schunk_refresh(blosc2_schunk *schunk)#

Re-sync the cached counters (nchunks, nbytes, cbytes) and metalayers of a disk-based super-chunk when another handle — possibly in another process — has changed it.

This gives a deterministic sync point for readers in a single-writer, multiple-readers (SWMR) workflow: after calling it, the counters in schunk reflect the current on-disk state. Data-access functions already do this implicitly, so calling it is only needed to observe changes without touching data (e.g. when polling).

A no-op for super-chunks not backed by an on-disk frame.

Parameters:
  • schunk – The super-chunk to refresh.

Returns:

1 if the counters were re-synced, 0 if they were already current, or a negative error code.