Skip to main content

Library for read compressed stream and write compressed chunks.

Project description

Light Compressor

This library is designed to provide optimal decompression and compression speed for data streams from databases and files. My project requires maximum-speed processing of byte streams and transferring compressed data to another stream. After testing all available solutions, I found their speed unsatisfactory, so I optimized the existing implementation to achieve better performance.

The stream reader use direct sequential reading from the stream with explicit size indication. This meets all requirements for my project. Supported compression formats: LZ4 and ZSTD only.

Examples

File detect compression only

from light_compressor import auto_detector
fileobj = open("some_path_to_file.bin", "rb")
compressor_method = auto_detector(fileobj)

File reading

When reading from files, automatic compression format detection is available (checks for LZ4/ZSTD signatures or no compression):

from light_compressor import define_reader
fileobj = open("some_path_to_file.bin", "rb")
decompressed_stream = define_reader(fileobj)

File writing

from light_compressor import (
    LZ4Compressor,
    ZSTDCompressor,
)
# some data in bytes
bytes_data: list[bytes]
# for example we using ZSTDCompressor
compressor = ZSTDCompressor()
fileobj = open("some_path_to_file.bin", "wb")

for data in compressor.send_chunks(bytes_data):
    fileobj.write(data)

print("Original size is:", compressor.decompressed_size)
print("Compressed size is:", fileobj.tell())

fileobj.close()

Stream reading

For stream processing, the compression method must be explicitly specified

from light_compressor import (
    define_reader,
    CompressionMethod,
)
compressed_stream: urllib3.response.HTTPResponse
# Get decompressed file-like object from ZSTD-compressed stream
decompressed_stream = define_reader(compressed_stream, CompressionMethod.ZSTD)

Stream writing

from light_compressor import (
    define_writer,
    CompressionMethod,
)
# some data in bytes
bytes_data: list[bytes]
# Get generator yielding ZSTD-compressed byte chunks
compressed_stream = define_writer(bytes_data, CompressionMethod.ZSTD)

Installation

From pip

pip install light-compressor

From local directory

pip install .

From git

pip install git+https://github.com/0xMihalich/light_compressor

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

light_compressor-0.0.1.4.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

light_compressor-0.0.1.4-cp310-cp310-win_amd64.whl (146.6 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file light_compressor-0.0.1.4.tar.gz.

File metadata

  • Download URL: light_compressor-0.0.1.4.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for light_compressor-0.0.1.4.tar.gz
Algorithm Hash digest
SHA256 d6539737812772f9e30c4360de8d52b62b929a1ff555226c19460d5e1ad42a13
MD5 5950a2dd14f539f583b9c9ef59d73014
BLAKE2b-256 e515044056351a21b8ff9f4417f09bab290011a1ee1e0a40fc8328b961df3bdb

See more details on using hashes here.

File details

Details for the file light_compressor-0.0.1.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for light_compressor-0.0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8724b755a4e376906bbdfee99c2230ec29deb04173ecdf097ac59fa9b7cd1c51
MD5 53a51ae796ece178016d8fce4621394f
BLAKE2b-256 2e1af2c35e0cab4d94584b9e0b533b40de7057b98029744ddc329042e488395d

See more details on using hashes here.

Supported by

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