Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.87 KB

File metadata and controls

52 lines (40 loc) · 1.87 KB

Subprocess Utilities for PKLib

This directory contains Python utilities and a demonstration script for working with the PKLib compression and decompression binaries.

Files

pypklib.py

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.

Functions:

  • implode(data, ctype, dict_bits):

    • Compresses data using the PKLib implode algorithm.
    • Arguments:
      • data (bytes or str): The data to compress.
      • ctype (int): Compression type. Use 0 for binary or 1 for ASCII.
      • dict_bits (int): Dictionary size. Use 4, 5, or 6 for 1024, 2048, or 4096 bytes, respectively.
    • Returns: Compressed data as bytes.
  • explode(compressed_data):

    • Decompresses data using the PKLib explode algorithm.
    • Arguments:
      • compressed_data (bytes): The compressed data to decompress.
    • Returns: Decompressed data as bytes.

demo.py

This script demonstrates how to use the pypklib.py module to compress and decompress data.

Example Usage:

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!"

How to Use

  1. Ensure the pklib_implode and pklib_explode binaries are compiled and located in the src directory.
  2. Make sure the binaries are executable. If not, you can set the permissions manually:
    chmod +x ../src/pklib_implode ../src/pklib_explode
  3. Run the demo.py script to see the compression and decompression in action:
    python3 demo.py

Notes

  • Ensure that the src directory is correctly structured and accessible from the subproc directory.