blosc2.compress#
- blosc2.compress(src: object, typesize: int = 8, clevel: int = 1, filter: Filter = Filter.SHUFFLE, codec: Codec = Codec.ZSTD) str | bytes #
Compress the given source data with specified parameters.
- Parameters:
src¶ (bytes-like object) – The data to be compressed. It must support the buffer interface.
typesize¶ (int (optional) from 1 to 255) – The data type size. The default is 8, 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
._ignore_multiple_size¶ (bool (optional)) – If True, ignores the requirement that the length of src must be a multiple of typesize.
- Returns:
out – The compressed data in as a Python str or bytes object.
- Return type:
str or bytes
- Raises:
Notes
The cname and shuffle parameters in python-blosc API have been replaced by
codec
andfilter
respectively. To setcodec
andfilter
, use the enumerationsCodec
andFilter
instead of the python-blosc API variables like 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