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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibcpy 3.10–3.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)
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.
fixInstall 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.
fixOpen 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.
fixEnsure 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.