SChunk.update_chunk#

SChunk.update_chunk(nchunk: int, chunk: bytes) int#

Update an existing chunk in the SChunk.

Parameters:
  • nchunk (int) – The index of the chunk to be updated.

  • chunk (bytes object) – The new compressed chunk that will replace the old chunk’s content.

Returns:

out – The number of chunks in the SChunk.

Return type:

int

Raises:

RunTimeError – If a problem is detected.

Examples

>>> import blosc2
>>> import numpy as np
>>> nchunks = 5
>>> chunk_size = 200 * 1000 * 4
>>> data = np.arange(nchunks * chunk_size // 4, dtype=np.int32)
>>> cparams = blosc2.CParams(typesize=4)
>>> schunk = blosc2.SChunk(chunksize=chunk_size, data=data, cparams=cparams)
>>> f"Initial number of chunks: {schunk.nchunks}"
Initial number of chunks: 5
>>> c_index = 1
>>> new_data = np.full(chunk_size // 4, fill_value=c_index, dtype=np.int32).tobytes()
>>> compressed_data = blosc2.compress2(new_data, typesize=4)
>>> # Update the 2nd chunk (index 1) with new data
>>> nchunks = schunk.update_chunk(c_index, compressed_data)
>>> f"Number of chunks after update: {nchunks}"
Number of chunks after update: 5