SChunk.insert_data#

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

Insert the data in the specified position in the SChunk.

Parameters:
  • nchunk (int) – The index at which the chunk will be inserted.

  • data (bytes object) – The data that will be compressed and inserted as a chunk.

  • copy (bool) – Whether to make an internal copy of the chunk to insert it or not.

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
>>> # Create an SChunk with 2 chunks
>>> data = np.arange(400 * 1000, dtype=np.int32)
>>> cparams = blosc2.CParams(typesize=4)
>>> schunk = blosc2.SChunk(chunksize=200*1000*4, data=data, cparams=cparams)
>>> # Create a new array to insert into the second chunk of the SChunk
>>> new_data = np.arange(200 * 1000, dtype=np.int32)
>>> # Insert the new data at position 1, compressing it
>>> schunk.insert_data(1, new_data, copy=True)
>>> # Verify the total number of chunks after insertion
>>> schunk.nchunks
3