SChunk.insert_chunk#

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

Insert an already compressed chunk into the SChunk.

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

  • chunk (bytes object) – The compressed chunk.

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)
>>> # Get a compressed chunk from the SChunk
>>> chunk = schunk.get_chunk(0)
>>> # Insert a chunk in the second position (index 1)"
>>> schunk.insert_chunk(1, chunk)
>>> # Verify the total number of chunks after insertion
>>> schunk.nchunks
3