Metadata-Version: 2.4
Name: light_compressor
Version: 0.0.1.3
Summary: Library for read compressed stream and write compressed chunks.
Author-email: 0xMihalich <bayanmobile87@gmail.com>
License: MIT License
        
        Copyright (c) 2025 0xMihalich
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/0xMihalich/light_compressor
Project-URL: Documentation, https://github.com/0xMihalich/light_compressor#readme
Project-URL: Repository, https://github.com/0xMihalich/light_compressor
Project-URL: Changelog, https://github.com/0xMihalich/light_compressor/blob/main/CHANGELOG.md
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cffi>=2.0.0
Requires-Dist: lz4>=4.4.4
Requires-Dist: zstandard>=0.25.0
Dynamic: license-file

# 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 reading

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

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

### File writing

```python
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

```python
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

```python
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

```bash
pip install light-compressor
```

From local directory

```bash
pip install .
```

From git

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