blosc2.schunk.SChunk.to_cframe#

SChunk.to_cframe() bytes#

Get a bytes object containing the serialized SChunk instance.

Returns:

out – The buffer containing the serialized SChunk instance.

Return type:

bytes

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(data=data, cparams=cparams)
>>> # Serialize the SChunk instance to a bytes object
>>> serialized_schunk = schunk.to_cframe()
>>> f"Serialized SChunk length: {len(serialized_schunk)} bytes"
Serialized SChunk length: 14129 bytes
>>> # Create a new SChunk from the serialized data
>>> deserialized_schunk = blosc2.schunk_from_cframe(serialized_schunk)
>>> start = 500
>>> stop = 505
>>> sl_bytes = deserialized_schunk[start:stop]
>>> sl = np.frombuffer(sl_bytes, dtype=np.int32)
>>> res = data[start:stop]
>>> f"Original slice: {res}"
Original slice: [500 501 502 503 504]
>>> f"Deserialized slice: {sl}"
Deserialized slice: [500 501 502 503 504]