Registry / serialization / unlzw3

unlzw3

JSON →
library0.2.3pypypi✓ verified 24d ago

unlzw3 is a pure Python decompression module for .Z files compressed using the Unix compress utility. Unlike the faster, but often Linux-specific, `unlzw` library using Python CFFI, unlzw3 is slower but offers cross-platform compatibility on any system running Python, including Windows. The current version is 0.2.3, released in December 2024, indicating active maintenance.

pip install unlzw3
INSTALL
IMPORT
SIG · UNLZW3
U
unlzw3
serializationpythonv0.2.3
Install
1.5s avg
Import
14ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.014s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unlzw
from unlzw3 import unlzw

Decompresses a .Z file (Unix compress utility format) into a UTF-8 decoded string. The input to `unlzw` should be bytes, typically read from a .Z file. The quickstart provides a runnable example, noting that for actual functionality, a properly LZW-compressed .Z file is required.

import os from pathlib import Path from unlzw3 import unlzw # Create a dummy .Z file for demonstration (replace with your actual file) # This is a simplification; real .Z files are generated by 'compress' # For a true .Z file, you'd use a real compressed file. # Example: if you have 'data.txt' and run 'compress data.txt', you get 'data.txt.Z' # For this quickstart, we'll assume 'example.txt.Z' exists. # Example: decompress a local .Z file # Assuming 'example.txt.Z' is in the current directory # In a real scenario, ensure 'example.txt.Z' exists and contains valid LZW compressed data. # Let's simulate a simple .Z file if it doesn't exist for the example to be runnable. # NOTE: This compressed data is NOT a real .Z file generated by `compress` utility, # but it allows the `unlzw` function to run without error for demonstration purposes. # A real .Z file would contain specific LZW headers and algorithm output. # For a proper test, you would need a pre-compressed .Z file. # Here, we'll just demonstrate the function call structure. compressed_data_path = Path('example.txt.Z') # To make this runnable without needing an actual `compress` utility, # we'll create a placeholder byte array that the `unlzw` function *could* process # if it were valid LZW data. For a true test, replace this with `compressed_data_path.read_bytes()` # after creating a valid .Z file. # For a proper example: # 1. Create a text file: `echo "Hello, unlzw3!" > original.txt` # 2. Compress it using system utility: `compress original.txt` (creates `original.txt.Z`) # 3. Then use `compressed_data = Path('original.txt.Z').read_bytes()` # For demonstration purposes, creating a dummy file (won't be a valid .Z for real uncompression) # This part is to make the quickstart self-contained and runnable, # but highlights the *type* of data expected by unlzw, not its actual content. if not compressed_data_path.exists(): # This is *not* real LZW compressed data, just bytes to make the example runnable. # In a real scenario, `compressed_data` would come from `read_bytes()` of a real .Z file. dummy_content = b'\x1f\x9d\x90\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Hello, unlzw3!' compressed_data_path.write_bytes(dummy_content) try: compressed_data = compressed_data_path.read_bytes() uncompressed_text = unlzw(compressed_data) print("Decompressed data:", uncompressed_text) except Exception as e: print(f"Error during decompression: {e}") print("Note: For proper decompression, `example.txt.Z` must be a valid LZW-compressed file.") # Clean up the dummy file if compressed_data_path.exists(): os.remove(compressed_data_path)
Debug
Known issues
gotchaPerformance difference compared to CFFI-based or system utilities. `unlzw3` is a pure Python implementation and is significantly slower than `unlzw` (which uses CFFI) or external system utilities like `uncompress` or `gzip` for decompressing .Z files. For high-throughput or large file operations, consider external processes or compiled alternatives.
fix
For performance-critical applications, evaluate using `subprocess` to call system utilities (`uncompress`, `gzip`) or consider the `unlzw` library if a C compiler and platform-specific dependencies are acceptable.
affects: All versions
gotchaInput data type and output encoding. The `unlzw` function expects binary data (bytes) as input, typically obtained by reading a .Z file in binary mode (e.g., `Path('file.Z').read_bytes()`). It returns a UTF-8 decoded string, assuming the original compressed content was text.
fix
Always provide binary data (bytes) to `unlzw`. If the original content was not UTF-8 encoded text, additional decoding might be required after decompression, or the decoded string might contain mojibake.
affects: All versions
gotchaConfusion with `unlzw` library. While both `unlzw` and `unlzw3` handle .Z files, `unlzw3` is pure Python and cross-platform, whereas `unlzw` relies on CFFI, potentially offering faster performance but with platform-specific build requirements or pre-compiled binaries.
fix
Choose `unlzw3` for maximum compatibility and ease of installation across different operating systems without external compilation needs. Opt for `unlzw` if performance is paramount and CFFI dependencies are manageable.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'unlzw3'
The `unlzw3` package is not installed in the current Python environment or there is a typo in the import statement.
fix
Install the package using pip: `pip install unlzw3`
AttributeError: 'str' object has no attribute 'read'
The `unlzw3.unlzw()` function expects either a file-like object (e.g., an opened file in binary mode) or a bytes-like object, but a string (likely a filename) was passed directly.
fix
Open the file in binary read mode and pass the file object, or read the file content into bytes first:
```python
# Option 1: Pass file object
import unlzw3
with open('file.Z', 'rb') as f:
    decompressed_data = unlzw3.unlzw(f)

# Option 2: Pass bytes directly
# with open('file.Z', 'rb') as f:
#     compressed_bytes = f.read()
# decompressed_data = unlzw3.unlzw(compressed_bytes)
```
unlzw3.LZWError: Bad magic number
The input file or bytes provided to `unlzw3.unlzw()` is not a valid `.Z` (LZW compressed) file or stream, or it is corrupted at the header.
fix
Ensure the input data is a genuine LZW-compressed `.Z` file. Verify the file's integrity and type before attempting decompression.
Upgrade
Version history
0.2.3latest on PyPI · released Dec 20, 2024
Audit
Dependencies
PythonrequiredRequires Python 3.9 or newer.
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
unlzw3 — pip install unlzw3 · libregistry