cmp
File-oriented gzip and zlib compression via host tools - shells out to system gzip or python3 zlib to compress or decompress files by path. For native in-process compression across multiple algorithms, see cmpz.
Load with: use cmp
What this module does
cmp provides simple file-to-file compression by delegating to external
host tools. Gzip operations call the system gzip binary; zlib operations
invoke a one-liner python3 -c script using Python's built-in
zlib module. The high-level helper writes a string to a temporary file
and then gzip-packs it to the destination, removing the temp file afterwards.
Because all operations go through shell processes, there is no in-process memory
overhead for large files, but you need gzip and python3
available on PATH.
Quick example
use cmp
# Gzip-compress a file
cmpgz("input.txt", "input.txt.gz")
# Gzip-decompress
cmpgz("input.txt.gz", "input.txt")
# Zlib compress/decompress files
cmcmp("raw.bin", "raw.bin.zlib")
cmcmp("raw.bin.zlib", "raw.bin")
# Compress a string directly to a .gz file
cmpgz("Hello, world!", "hello.gz")
Functions
Gzip
cmpgz(src, dst) - compress
Runs gzip -c {src} > {dst}. Both paths are shell-quoted. Returns dst.
cmpgz(src, dst) - decompress
Runs gzip -dc {src} > {dst}. Returns dst.
cmpgz(s, dst) - string → gz
Writes string s to a temporary file (dst + ".tmp_plain"), gzip-packs it to dst, then removes the temporary file. Returns dst.
Zlib
cmcmp(src, dst) - compress
Reads src, compresses with Python's zlib.compress, writes to dst. Returns dst.
cmcmp(src, dst) - decompress
Reads src, decompresses with Python's zlib.decompress, writes to dst. Returns dst.
Notes
- Requires
gzipandpython3on the system PATH. - For in-process compression without external dependencies, use
cmpzwhich supports gzip, brotli, zstd, lz4, bzip2, xz, and 7z natively. - Requires
txt,fs, andos.