blosc2.open#

blosc2.open(urlpath, mode='a', offset=0, **kwargs)#

Open a persistent SChunk (or NDArray).

Parameters:
  • urlpath (str) – The path where the SChunk (or NDArray) is stored.

  • mode (str, optional) – The open mode.

  • offset (int, optional) – An offset in the file where super-chunk or array data is located (e.g. in a file containing several such objects).

  • kwargs (dict, optional) –

    Keyword arguments supported: cparams: dict

    A dictionary with the compression parameters, which are the same that can be used in the compress2() function. Typesize and blocksize cannot be changed.

    dparams: dict

    A dictionary with the decompression parameters, which are the same that can be used in the decompress2() function.

Notes

This is just a ‘logical’ open, so no there is not a close() counterpart because currently there is no need for it.

Returns:

out – The SChunk or NDArray (in case there is a “b2nd” metalayer”).

Return type:

SChunk or NDArray

Examples

>>> import blosc2
>>> import numpy as np
>>> storage = {"contiguous": True, "urlpath": "b2frame", "mode": "w"}
>>> nelem = 20 * 1000
>>> nchunks = 5
>>> chunksize = nelem * 4 // nchunks
>>> data = np.arange(nelem, dtype="int32")
>>> # Create SChunk and append data
>>> schunk = blosc2.SChunk(chunksize=chunksize, data=data.tobytes(), **storage)
>>> # Open SChunk
>>> sc_open = blosc2.open(urlpath=storage["urlpath"])
>>> for i in range(nchunks):
...     dest = np.empty(nelem // nchunks, dtype=data.dtype)
...     schunk.decompress_chunk(i, dest)
...     dest1 = np.empty(nelem // nchunks, dtype=data.dtype)
...     sc_open.decompress_chunk(i, dest1)
...     np.array_equal(dest, dest1)
True
True
True
True
True