This directory contains Python utilities and a demonstration script for working with the PKLib compression and decompression binaries.
This Python module provides functions to compress and decompress data using the PKLib binaries. It relies on subprocess calls to the pklib_implode and pklib_explode binaries located in the src directory.
-
implode(data, ctype, dict_bits):- Compresses data using the PKLib
implodealgorithm. - Arguments:
data(bytes or str): The data to compress.ctype(int): Compression type. Use0for binary or1for ASCII.dict_bits(int): Dictionary size. Use4,5, or6for 1024, 2048, or 4096 bytes, respectively.
- Returns: Compressed data as bytes.
- Compresses data using the PKLib
-
explode(compressed_data):- Decompresses data using the PKLib
explodealgorithm. - Arguments:
compressed_data(bytes): The compressed data to decompress.
- Returns: Decompressed data as bytes.
- Decompresses data using the PKLib
This script demonstrates how to use the pypklib.py module to compress and decompress data.
from pypklib import implode, explode
data = b"your data here"
compressed = implode(data, 1, 5)
decompressed = explode(compressed)
assert data == decompressed, "Decompressed data does not match the original!"- Ensure the
pklib_implodeandpklib_explodebinaries are compiled and located in thesrcdirectory. - Make sure the binaries are executable. If not, you can set the permissions manually:
chmod +x ../src/pklib_implode ../src/pklib_explode
- Run the
demo.pyscript to see the compression and decompression in action:python3 demo.py
- Ensure that the
srcdirectory is correctly structured and accessible from thesubprocdirectory.