Skip to main content

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 LZHAMDecompressor 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.

Metadata

Release files for pylzham 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylzham 0.1.3
File Size Uploaded
pylzham-0.1.3.tar.gz 112.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylzham 0.1.3
File Interpreter ABI Platform
pylzham-0.1.3-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details

Total release size: 187.2 kB

Release files / pylzham-0.1.3.tar.gz

Download URL pylzham-0.1.3.tar.gz
Size 112.0 kB
Tags Source
SHA-256 checksum
How to use checksums
af4828d4b0e158a938550d9299e5da82bdc9fbb375fe6e3da429012839fbade2
BLAKE2b-256 checksum
How to use checksums
57940bfab1a4bb4dd12358433ac9d54a7ab928fe4bc9e89d0d11578dab335fb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release files / pylzham-0.1.3-cp310-cp310-win_amd64.whl

Download URL pylzham-0.1.3-cp310-cp310-win_amd64.whl
Size 75.1 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
fe877259db418c4a1b11e89a8a972628cac364040de00b3b83d859b93264f236
BLAKE2b-256 checksum
How to use checksums
1946f8b58d1eb8fc073fb369ca644b9fa4e180c36c01538d39304174de668f12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page