blosc2.open#

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

Open an already persistently stored SChunk.

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

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

  • 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.

Examples

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