Build a binary-safe sliding-window compressor/decompressor CLI with reproducible ratio reporting. Use when tasks require lossless round-trip validation across mixed text/binary files and graded output JSON.
Use this skill when a task asks for:
compress / decompress command-line toolresults.json with compression ratiosCreate a deterministic on-disk format.
Implement compression with a bounded match search.
MIN_MATCH, MAX_MATCH, and WINDOW_SIZE.MAX_CANDIDATESImplement decompression with strict safety checks.
offset <= 0 or offset > len(output)).Keep all file I/O binary.
"rb" / "wb" for both text and binary fixtures.Expose exact CLI contract.
python3 compressor.py compress <input_file> <output_file>python3 compressor.py decompress <input_file> <output_file>Run full round-trip on every required fixture.
cmp -s (or equivalent bytewise check).Generate results.json from actual file sizes.
compressed_size / original_size for each required file key.small_ratio, medium_ratio, large_ratio, binary_ratio).Rebinding outer variables inside nested functions (Python closure trap).
In one run, out += ... inside a nested flush_literals() caused:
cannot access local variable 'out' where it is not associated with a value.
Prevent this by mutating instead of rebinding (out.extend(...)) or declaring scope explicitly.
Continuing pipeline after compression failed.
When .lz files were never produced, downstream decompress and ratio steps failed with FileNotFoundError.
Gate each stage: stop and fix the first failure before computing ratios.
Writing ratios not tied to produced artifacts.
Tests checked that reported JSON ratios matched actual compressed files.
Compute ratios directly from filesystem sizes after successful compression.
Skipping binary-safe handling.
Text-mode I/O can silently corrupt non-text fixtures. Always use byte mode.
Run verification in the same order tests logically require:
Artifact existence
compressor.py exists at required path.results.json exists.Round-trip correctness (per file)
cmp -s original decompressed and require exit code 0.Compression-ratio requirement
<= 0.70.JSON format + consistency
results.json values.This strategy matched all observed successful runs and directly prevents the only observed failure mode.