This sub-package provides the capability to compress and decompress data using the block specification.
Because the LZ4 block format doesn’t define a container format, the Python bindings will by default insert the original data size as an integer at the start of the compressed payload, like most other bindings do (Java…). However, it is possible to disable this functionality.
To use the lz4 block format bindings is straightforward:
.. doctest::
>>> import lz4.block
>>> import os
>>> input_data = 20 * 128 * os.urandom(1024) # Read 20 * 128kb
>>> compressed_data = lz4.block.compress(input_data)
>>> output_data = lz4.block.decompress(compressed_data)
>>> input_data == output_data
True
lz4.block.
compress
(source, mode='default', acceleration=1, compression=0, return_bytearray=False)¶Compress source, returning the compressed data as a string. Raises an exception if any error occurs.
Parameters: | source (str, bytes or buffer-compatible object) – Data to compress |
---|---|
Keyword Arguments: | |
|
|
Returns: | Compressed data. |
Return type: | bytes or bytearray |
lz4.block.
decompress
(source, uncompressed_size=-1, return_bytearray=False)¶Decompress source, returning the uncompressed data as a string. Raises an exception if any error occurs.
Parameters: | source (str, bytes or buffer-compatible object) – Data to decompress. |
---|---|
Keyword Arguments: | |
|
|
Returns: | Decompressed data. |
Return type: | bytes or bytearray |