blosc2.decompress(src, dst=None, as_bytearray=False)#

Decompresses a bytes-like compressed object.

  • src (bytes-like object) – The data to be decompressed. Must be a bytes-like object that supports the Python Buffer Protocol, like bytes, bytearray, memoryview, or numpy.ndarray.

  • dst (NumPy object or bytearray) – The destination NumPy object or bytearray to fill, the length of which must be greater than 0. The user must make sure that it has enough capacity for hosting the decompressed data. Default is None, meaning that a new bytes or bytearray object is created, filled and returned.

  • as_bytearray (bool (optional)) – If this flag is True then the return type will be a bytearray object instead of a bytes object.


out – If dst is None, the decompressed data in form of a Python str / bytes object. If as_bytearray is True then this will be a bytearray object.

If dst is not None, it will return None because the result will already be in dst.

Return type:

str/bytes or bytearray

  • RuntimeError – The compressed data is corrupted or the output buffer is not large enough. Could not get a bytes object.

  • TypeError – If src does not support Buffer Protocol.

  • ValueError – If the length of src is smaller than the minimum. If dst is not None and its length is 0.


>>> import array, sys
>>> a = array.array('i', range(1000*1000))
>>> a_bytesobj = a.tobytes()
>>> c_bytesobj = blosc2.compress(a_bytesobj, typesize=4)
>>> a_bytesobj2 = blosc2.decompress(c_bytesobj)
>>> a_bytesobj == a_bytesobj2
>>> b"" == blosc2.decompress(blosc2.compress(b""))
>>> b"1"*7 == blosc2.decompress(blosc2.compress(b"1"*7))
>>> type(blosc2.decompress(blosc2.compress(b"1"*7),
...                        as_bytearray=True)) is bytearray
>>> import numpy as np
>>> arr = np.arange(10)
>>> comp_arr = blosc2.compress(arr)
>>> dest = np.empty(arr.shape, arr.dtype)
>>> blosc2.decompress(comp_arr, dst=dest)
>>> np.array_equal(arr, dest)