Skip to main content

Python 3 Wrapper for LZHAM Codec

Project description

PyLZHAM

PyLZHAM is a python 3 wrapper for the LZHAM Compression Codec

Installation

In order to install pylzham, you'll simply need to use the following command

python -m pip install pylzham

Note: PyLZHAM use C++ extension which means python need a compiler to build this module

Usage

Compression

You can easily compress data using the following snippet:

>>> import lzham
>>> lzham.compress(b'yourdatahere' * 100)
b'@\x0b\x9f\x85\x07\x96\xf7W&F\x17F\x16\x86P\x07&W\x98(C\xf4\x03\xf7\xf4\x02m\x98\xc0P\xeb\xf9$'

However if you need to compress many files/data, using the LZHAMCompressor class might be a better idea. Here is a quick example:

>>> from lzham import LZHAMCompressor
>>> compressor = LZHAMCompressor()
>>> compressor.compress(b'yourdatahere' * 100)
b'@\x0b\x9f\x85\x07\x96\xf7W&F\x17F\x16\x86P\x07&W\x98(C\xf4\x03\xf7\xf4\x02m\x98\xc0P\xeb\xf9$'
>>> compressor.compress(b'yourotherdata' * 100)
b'@\x07\xcd\xd9\x07\x96\xf7W&\xf7F\x86W&D\xc6\x17F\x17\x98(D\x03\xf7\xf4\x03\xf7\xf4\x01\x98\xc03i*k'
Using compression option

If you wanna set compression options you should use a compression filter. Filters support the following options (specified as additional entries in the dictionary representing the filter):

  • dict_size_log2
  • level
  • table_update_rate
  • max_helper_threads
  • table_max_update_interval
  • table_update_interval_slow_rate

For more information about thoses options you can look there.

Here is an example of using filters with both lzham.compress and LZHAMCompressor:

 >>> filters = {'dict_size_log2': 18}
 >>> lzham.compress(b'yourdata', filters)
 >>> compressor = lzham.LZHAMCompressor(filters)
 >>> compressor.compress(b'yourdata')

Decompression

You can easily decompress data using the following snippet:

>>> import lzham
>>> lzham.decompress(b'D\xad\xc0\x00\x07FW7@\x07i1\x98\xc0f\xb1\x11\x81', 40)
b'testtesttesttesttesttesttesttesttesttest'

Note: Since there is no offical header for LZHAM you have to give the decompressed data size to the lib (40 in our case).

However if you need to decompress many files/data, using the LZHAMDeompressor class might be a better idea. Here is a quick example:

>>> from lzham import LZHAMDecompressor
>>> decompressor = LZHAMDecompressor()
>>> decompressor.decompress(b'D\xad\xc0\x00\x07FW7@\x07i1\x98\xc0f\xb1\x11\x81', 40)
b'testtesttesttesttesttesttesttesttesttest'
>>> decompressor.decompress(b'D\xad\xc0\x00\x07FW7@\x07i1\x98\xc0f\xb1\x11\x81', 40)
b'testtesttesttesttesttesttesttesttesttest'
Using decompression option

If you wanna set decompression options you should use a decompression filter. Filters support the following options (specified as additional entries in the dictionary representing the filter):

  • dict_size_log2
  • table_update_rate
  • table_max_update_interval
  • table_update_interval_slow_rate
  • compute_adler32_during_decomp
  • unbuffered_decompression

For more information about thoses options you can look there.

Here is an example of using filters with both lzham.decompress and LZHAMDecompressor:

 >>> filters = {'dict_size_log2': 18}
 >>> lzham.decompress(b'D\xad\xc0\x00\x07FW7@\x0fi3\x98\xc0f\xb1\x11\x81', 40, filters)
>>> decompressor = lzham.LZHAMDecompressor(filters)
>>> decompressor.decompress(b'D\xad\xc0\x00\x07FW7@\x0fi3\x98\xc0f\xb1\x11\x81', 40)

If you need to modify your LZHAMDecompressor instance filters you can simply call its reinit function like this:

>>> decompressor.reinit(filters)

Note

I'm a C++ newbie so my code might be really trash. If you have any bug to report feel free to contact me at @GaLaXy1036#1601 on Discord.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylzham-0.1.2.tar.gz (110.3 kB view details)

Uploaded Source

Built Distribution

pylzham-0.1.2-cp36-cp36m-win_amd64.whl (74.9 kB view details)

Uploaded CPython 3.6m Windows x86-64

File details

Details for the file pylzham-0.1.2.tar.gz.

File metadata

  • Download URL: pylzham-0.1.2.tar.gz
  • Upload date:
  • Size: 110.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.8

File hashes

Hashes for pylzham-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f6cf8b0f7a6f83aba137bba6882075f31803aa5fc8f9d10b887e146db30db592
MD5 86b76e6058072eca0e1d9faab287c8a6
BLAKE2b-256 c79f8298266a7bd3ab96bbd3be8e42fabae83017b85f6b9fcda681bdc56c9da4

See more details on using hashes here.

Provenance

File details

Details for the file pylzham-0.1.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pylzham-0.1.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 74.9 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.8

File hashes

Hashes for pylzham-0.1.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c7b4c5a90b29a2b4e169307686fdc59b36ce646bb72467275ca4ef9e80eb0e7a
MD5 005dda9d0fa914de0426c6947e0da0f1
BLAKE2b-256 7fc6d9e7e36d3797b589bea4d587f45f430297964553d99bc19d0ef83092c4cb

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page