blosc2.compress#
- blosc2.compress(src, typesize=None, clevel=9, filter=Filter.SHUFFLE, codec=Codec.BLOSCLZ)#
Compress src, with a given type size.
- Parameters:
src¶ (bytes-like object (supporting the buffer interface)) – The data to be compressed.
typesize¶ (int (optional) from 1 to 255) – The data type size. The default is 1, or src.itemsize if it exists.
clevel¶ (int (optional)) – The compression level from 0 (no compression) to 9 (maximum compression). The default is 9.
filter¶ (
Filter
(optional)) – The filter to be activated. The default isFilter.SHUFFLE
.codec¶ (
Codec
(optional)) – The compressor used internally in Blosc. The default isCodec.BLOSCLZ
.
- Returns:
out – The compressed data in form of a Python str / bytes object.
- Return type:
str / bytes
- Raises:
Notes
The cname and shuffle parameters in python-blosc API have been replaced by
codec
andfilter
respectively. To setcodec
andfilter
, the enumeratesCodec
andFilter
have to be used instead of the python-blosc API variables such as blosc.SHUFFLE forfilter
or strings like “blosclz” forcodec
.Examples
>>> import array, sys >>> a = array.array('i', range(1000*1000)) >>> a_bytesobj = a.tobytes() >>> c_bytesobj = blosc2.compress(a_bytesobj, typesize=4) >>> len(c_bytesobj) < len(a_bytesobj) True