blosc2.schunk_from_cframe#
- blosc2.schunk_from_cframe(cframe: bytes | str, copy: bool = False) SChunk #
Create a SChunk instance from a contiguous frame buffer.
- Parameters:
- Returns:
out – A new SChunk containing the data passed.
- Return type:
See also
Examples
>>> import numpy as np >>> import blosc2 >>> 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) >>> serialized_schunk = schunk.to_cframe() >>> print(f"Serialized SChunk length: {len(serialized_schunk)} bytes") Serialized SChunk length: 14129 bytes >>> deserialized_schunk = blosc2.schunk_from_cframe(serialized_schunk) >>> start = 1000 >>> stop = 1005 >>> sl_bytes = deserialized_schunk[start:stop] >>> sl = np.frombuffer(sl_bytes, dtype=np.int32) >>> print("Slice from deserialized SChunk:", sl) Slice from deserialized SChunk: [1000 1001 1002 1003 1004] >>> expected_slice = data[start:stop] >>> print("Expected slice:", expected_slice) Expected slice: [1000 1001 1002 1003 1004]