compact_pro is a clean-room, cross-platform Compact Pro (.cpt) implementation.
- Pure Zig core for archive/container/codec logic.
- C ABI (FFI) for embedding.
- C CLI named
compact-profor all filesystem and platform I/O.
- Mechatron Prime CI is the project's continuous-integration service: a self-hosted Nix build worker that builds every push to
yolo. It builds the flake attributes listed in.mechatron-prime/targets:- Linux x86_64: full unit and CLI test suite, plus a release build.
- Linux aarch64, Windows x86_64 and Windows aarch64: cross-compiled release builds.
- GitHub Actions (
.github/workflows/ci.yml) runs on native runners:- Linux x86_64, Linux aarch64 and macOS aarch64: Nix-based full test suite and release build.
- Windows x86_64: Zig unit tests, release build and a CLI smoke test.
- Windows aarch64: cross-compiled build artifact (not executed).
./buildDebug build:
./build --debugRun full test suite:
./testRun benchmark suite (speed + compression performance):
./bmcompact-pro
Usage:
compact-pro compress [--sidecar|--rsrc <path>|--xattr <name>] [--progress|--no-progress] [--force|-f] [-o <archive.cpt|->] <file...|->
compact-pro expand [--sidecar|--rsrc <path>|--xattr <name>] [--progress|--no-progress] <archive.cpt> [-d <outdir>] [--path <entry> ...]
compact-pro add [--sidecar|--rsrc <path>|--xattr <name>] [--progress|--no-progress] <archive.cpt> <file...>
compact-pro list <archive.cpt>
compact-pro verify <archive.cpt|-> (bounded-memory integrity check)
compact-pro --help
-
compress- Creates a new
.cptarchive from input files (or stdin via-). - Directory inputs are recursively expanded; archive paths are rooted at the input directory basename.
- Empty directories are captured via metadata trailer records and recreated on extraction.
- Default output behavior is no-clobber: if target archive exists, command fails.
- Use
--force(-f) to overwrite an existing output archive. - Prints completion stats to stderr: input bytes, compressed bytes, compressed percent, MB/s throughput, elapsed seconds.
- Progress:
--progressforces progress output to stderr.--no-progressdisables progress output.- default is progress on TTY stderr.
- live output renders phase bars with percent and ETA, e.g.
[=====>-----] 42% (ETA: 35s).
-ois optional; default output is derived from filename (or cwd for multi-input).- If
-ois provided without.cpt,.cptis appended automatically. -o -writes archive bytes to stdout.~-prefixed paths are expanded to home directory.- Preserves relative input paths as archive paths (for directory-aware extraction).
- Captures hierarchical metadata extension in an appended compatibility trailer outside normal Compact Pro entries.
- Trailer metadata includes file and directory records with per-field masks (permissions, ownership, timestamps, Apple flags, and NTFS attributes/timestamps when present).
- Creates a new
-
expand- Extracts archive contents into
-d <outdir>(default.). - Recreates metadata-recorded empty directories in addition to file-parent directories.
- Prints completion stats to stderr: compressed bytes, expanded bytes (
compressed -> expanded), expansion ratio, MB/s throughput, elapsed seconds. - Progress:
--progressforces progress output to stderr.--no-progressdisables progress output.- default is progress on TTY stderr.
- live output renders phase bars with percent and ETA.
--path <entry>may be repeated to extract only selected entries.- Entries are decoded on all CPU cores (up to 16) through
cp_archive_extract_parallel; output and errors are identical tocp_archive_extract. - Restores file and directory metadata from the appended trailer when present. If the trailer's CRC-32 does not match, it prints
warning: metadata trailer crc mismatch; metadata restore skippedand still extracts the (independently CRC-checked) file data. - Unsupported/unrestorable fields emit explicit warnings with the specific field name and do not abort data extraction.
- Extracts archive contents into
-
add- Adds files to an existing archive by rebuilding archive content via FFI.
- Directory inputs are recursively expanded before add.
- Progress:
--progressforces progress output to stderr.--no-progressdisables progress output.- default is progress on TTY stderr.
- live output renders phase bars with percent and ETA.
- Regenerates the appended metadata trailer so metadata remains synchronized after updates.
-
list- Lists archive entries and fork sizes.
- Metadata trailer is out-of-band and never appears as a normal archive entry.
- Prints trailer accounting line (
trailer_size,trailer_payload) at the end so on-disk overhead is explicit.
-
verify- Checks archive integrity (header CRC, every fork's decoding, per-file CRC) without extracting anything or loading the archive into memory.
- Uses the bounded-memory
cp_archive_verify_streamC API, which reads the archive through a range-read callback and returns the same error codes ascp_archive_extract. - Prints
ok<TAB>entries=N<TAB>bytes=Mon success; on failure printserror: verify failed: <reason> (archive offset N)to stderr and exits 1. The offset is where the failure was detected: just past the last byte consumed, or the start of the CRC-covered region for header and file CRC mismatches. - LZH bitstream damage is reported as
invalid lzh codebookorinvalid lzh huffman code(C codesCP_ERR_LZH_INVALID_CODEBOOK,CP_ERR_LZH_INVALID_HUFFMAN_CODE). -or@stdinreads the archive from stdin (buffered in memory, since stdin is not seekable).- Entries are verified on all CPU cores (
cp_archive_verify_stream_parallel), each worker using fixed 128 KiB of buffers; results and reported offsets are identical to sequential verification.
--sidecar: AppleDouble sidecar (._<name>)--rsrc <path>: explicit sidecar path--xattr <name>: Linux xattr key (Linux only)
Defaults:
- macOS: native resource fork path (
..namedfork/rsrc) for default behavior. - non-macOS: sidecar output on extraction; no implicit resource-fork input unless selected.
- RLE profile implemented for read/write.
- LZH profile implemented for read/write.
- On write, each fork is encoded as RLE first, then optionally LZH-over-RLE when strictly smaller.
- Multi-block LZH writer now follows legacy block termination semantics (
block_count >= 0x1fff0with token-cost overshoot permitted), matching The Unarchiver/unarexpectations. - Container entry-count fields follow legacy Compact Pro subtree-count semantics for root/directory metadata traversal.
- Metadata extension is appended as trailer bytes after canonical Compact Pro payload; legacy tools should ignore trailing bytes while this implementation restores metadata from that trailer.
- Trailer layout (version 2):
[payload][CRC-32 of payload, LE u32][magic "CPXTRLR1"][payload length, LE u32][version = 2, LE u32]. Version 1 trailers (no CRC field) from earlier releases are still read.verifyfails on a version 2 CRC mismatch.
./bmruns comparative benchmarks againstcompact-pro,zip, andgzip.- Captures:
- compress speed (
wall,user,system, throughput MiB/s) - extract speed (
wall,user,system, throughput MiB/s) - compression performance (output size and
out/inratio)
- compress speed (
- Persists history to
tests/benchmark/history.tsv. - Fails loudly on sudden drift (default 20%) versus the previous row unless accepted via
--acceptorBENCH_ACCEPT=1.