blosc2.C2Array.get_chunk#

C2Array.get_chunk(nchunk: int) bytes#

Get the compressed unidimensional chunk of a C2Array.

Parameters:

nchunk (int) – The index of the unidimensional chunk to retrieve.

Returns:

out – The requested compressed chunk.

Return type:

bytes

Examples

>>> import numpy as np
>>> import blosc2
>>> urlbase = "https://demo.caterva2.net/"
>>> path = "example/dir1/ds-3d.b2nd"
>>> a = blosc2.C2Array(path, urlbase)
>>>  # Get the compressed chunk from array 'a' for index 0
>>> compressed_chunk = a.get_chunk(0)
>>> f"Size of chunk {0} from a: {len(compressed_chunk)} bytes"
Size of chunk 0 from a: 160 bytes
>>> # Decompress the chunk and convert it to a NumPy array
>>> decompressed_chunk = blosc2.decompress(compressed_chunk)
>>> np.frombuffer(decompressed_chunk, dtype=a.dtype)
[ 0.  1.  5.  6. 20. 21. 25. 26.  2.  3.  7.  8. 22. 23. 27. 28. 10. 11.
  0.  0. 30. 31.  0.  0. 12. 13.  0.  0. 32. 33.  0.  0.]