blosc2.schunk.SChunk.update_data#

SChunk.update_data(nchunk: int, data: object, copy: bool) int#

Update the chunk in the specified position with the given data.

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

  • data (bytes object) – The data to be compressed and will replace the old chunk.

  • copy (bool) – Whether to make an internal copy of the chunk before updating it.

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 = 4
>>> 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: 4
>>> c_index = 1 # Update the 2nd chunk (index 1)
>>> new_data = np.full(chunk_size // 4, fill_value=c_index, dtype=np.int32).tobytes()
>>> nchunks = schunk.update_data(c_index, new_data, copy=True)
>>> f"Number of chunks after update: {schunk.nchunks}"
Number of chunks after update: 4