SChunk.insert_chunk#

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

Insert an already compressed chunk in the SChunk.

Parameters:
  • nchunk (int) – The position in 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 some problem was detected.

Examples

>>> import blosc2
>>> import numpy as np
>>> # Create an SChunk with 2 chunks
>>> data = np.arange(400 * 1000, dtype=np.int32)
>>> schunk = blosc2.SChunk(chunksize=200*1000*4, data=data, cparams={"typesize": 4})
>>> # 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