Each page covers synopsis, options, supported formats or extensions,
safety and placement rules (x) or compression profiles and refusals (c),
the progress display, exit statuses, environment and examples. c.1
renders its profile table with tbl.
make install now installs them to $(PREFIX)/share/man/man1 (MANDIR is
overridable), and make uninstall removes them.
The PKGBUILD now lives in its own AUR clone, next to the other AUR
packages, like those of the other own projects (prx, lazyntfy). It
builds from the server's tag tarball with a pinned sha256 instead of
a git source with SKIP.
Remove packaging/aur, the srcinfo Makefile target and the makepkg
ignore rules, and shorten the README section to a pointer to the AUR
package.
Describe what the package builds and installs, how to build it locally
with makepkg, and how to publish a release: tag it, regenerate
.SRCINFO, and push PKGBUILD and .SRCINFO to the AUR repository.
The PKGBUILD builds from the release tag (git+URL#tag=v$pkgver) and
follows the Arch Go package guidelines:
- PIE binaries, externally linked with makepkg's flags;
- -trimpath and a read-only module graph, with a module cache in
$srcdir;
- GOTOOLCHAIN=local, so makepkg never downloads a toolchain.
It stamps the version from pkgver, runs the test suite in check()
(-short skips the pseudo-terminal tests), and installs x, c and the
docs. .SRCINFO is generated from it.
libarchive is a dependency because x extracts most formats with bsdtar.
7zip, zip and the compressors are optional dependencies, each described
by the formats it enables. namcap's "libarchive may not be needed" is
expected: bsdtar is executed, not linked.
makepkg's output in packaging/aur (src/, pkg/, the source clone and
packages) is ignored.
Records the reasoning: the flaws of the old Oh My Zsh extract, the move
from Bash to Go, backend choices, staging and placement, --force
semantics, profiles, exclusion, the progress display and the testing
approach.
make check runs gofmt, go vet, staticcheck when installed, and all
tests. make install builds static, trimpath binaries and installs them
to ~/.local/bin (PREFIX and DESTDIR are honored).
Every type and profile is created and then checked with the format's
own tools, independently of x, and round-tripped through x. Tests also
cover naming, symlink inputs, refusals, backend failures, missing
dependencies, and exclusion behaving the same across tar, zip and 7z.
Tests cover:
- every format round trip;
- the placement rule, conflicts and --force merges;
- validation before extraction;
- corrupt archives and missing dependencies;
- every crafted escape;
- invocation from zsh;
- the progress display on a real pseudo-terminal, including -q and
NO_COLOR.
Formats that no common tool creates are written byte by byte: a minimal
RPM with a cpio payload, an uncompressed cabinet, a stored RAR 4
archive and a literal-code LZW stream. Path-traversal, absolute-path,
symlink and hard-link escapes are built with archive/tar and
archive/zip. No binary fixtures are stored.
TestMain builds x and c once. Each test gets its own directory, with
HOME redirected, so real files are never touched. Helpers cover:
- running the binaries and asserting status, stdout and stderr;
- comparing trees by type, content and symlink target;
- a tree of awkward names;
- a PATH that hides chosen programs, to simulate missing dependencies.
Tests pin:
- every compressor's arguments for every profile;
- the zip and 7z levels;
- the full tar, zip and 7z command lines, including names that start
with "-";
- the exclude pattern translation and type-resolution errors.
- The type comes from --type or the extension; a contradiction is an
error, and the output is never renamed.
- Each input is stored under its own resolved name.
- An existing output, an output inside an input, the output as an
input, duplicate names and the root directory are refused before
any work.
- Backends: GNU tar piped into the compressor, Info-ZIP zip once per
input, and 7-Zip.
- --exclude matches names at any depth, translated so the three
backends behave alike.
- The archive is built beside the output and renamed into place only
when complete.
The types are tar, tar.gz, tar.bz2, tar.xz, tar.zst, zip and 7z,
detected from case-insensitive suffixes. --fast, default and --best map
to each tool's own levels; "best" is the highest standard level, never
a memory-hungry mode (zstd --ultra, xz -e). xz and zstd use all cores.
Tests cover:
- the suffix table, including stems and lookalikes that must not
match;
- UDF detection on synthetic images;
- the exact argument vector of every backend;
- the .deb payload pattern and the "contains the source archive" guard.
- Every input, the destination and the needed backends are validated
before anything is extracted.
- Each archive is extracted into a private staging directory inside
the destination and moved into place only after the backend
succeeds, so corrupt, unsafe or interrupted archives leave nothing
behind.
- Placement: one top-level entry lands as itself, several land in a
directory named after the archive.
- Existing paths are never touched without --force, which merges, and
never touches the source archive.
- bsdtar runs with its secure defaults and without restoring
ownership. A .deb yields its data.tar payload, like dpkg-deb -x.
- The live progress display is shown on a terminal at normal
verbosity.
Formats are recognized by case-insensitive suffix, most specific first,
and the stem is kept for naming output.
Each format maps to one backend: bsdtar for tar, zip, cab, cpio, deb,
rpm and ISO 9660; 7-Zip for 7z, RAR and ISO images that carry UDF;
the reference decompressors for single files. UDF is detected from the
volume recognition sequence, because UDF-only images (Windows media)
would otherwise yield only their ISO 9660 README.
Tests use a fake terminal and an injected clock and /proc readers.
- Rendering: layout, gradient endpoints, bar width limits, truncation,
plain output without color, and the unknown-total and overshoot
states.
- Behavior: speed smoothing, accumulation across processes, the show
delay, erase sequences, messages printed above the display, and both
kinds of prompt.
Progress is the bytes a backend process has read (rchar in
/proc/PID/io), so every backend works unchanged; reads of successive
processes add up. Speed is smoothed with an exponential moving average.
- The display redraws every 80 ms, appears only after 250 ms, and
erases itself completely when stopped.
- Backend output goes through Writer, which prints whole lines above
the display.
- An unterminated line that stays put, or a backend opening /dev/tty,
is treated as a password prompt and stops the drawing.
A frame has three lines, in the style of github.com/programmersd21/zap:
- an operation badge, a braille spinner and the item;
- a bar blending Catppuccin blue to mauve over a dark track;
- a data / speed / ETA line, or "finishing…" once all input is read.
Rendering is a pure function of the frame. It falls back to plain text
without color, and truncates so no line wraps on narrow terminals.
Tests cover:
- an existing file or an empty directory blocks a no-replace rename;
- a read-only directory moves and keeps its mode;
- merges keep unrelated files and refuse type changes;
- a merge refuses to write through a destination symlink;
- removal of an unreadable tree leaves a symlink target's mode
untouched.
- RenameNoReplace uses renameat2(RENAME_NOREPLACE), so the existence
check and the rename are one atomic step; it falls back to
check-then-rename where the flag is unsupported.
- Move renames read-only directories, as found in ISO images, by
granting u+w for the rename and restoring the full mode afterwards.
- Merge implements --force: files replace files, directories merge,
a file never replaces a directory or the reverse, and symlinks in
the destination are never followed.
- RemoveAll makes read-only trees removable without following symlinks.
Tests cover data flowing through two stages, the rightmost failure
winning, a missing program, the working directory, and a cancelled
pipeline stopping within seconds instead of waiting for its stages.
Commands are argument vectors passed straight to exec, so file names
are never quoted or evaluated.
- Pipelines connect each stdout to the next stdin and, like a shell
with pipefail, fail if any stage fails, reporting the rightmost
failure ("tar exited with status 2").
- Cancelling the context sends SIGTERM, then kills after five seconds.
- PipelineIO takes explicit streams and reports the process IDs once
every stage has started.
Table tests cover:
- bundles, including one that ends in a value option;
- attached and empty values, values that look like options;
- permutation, "--" and a lone "-";
- every usage error message.
Options may follow operands, "--" ends them, short flags bundle (-qv),
and values may be separate, attached (-dDIR) or given with "=". Long
options are never abbreviated, so parsing stays predictable. Options
are returned in command-line order so that "last one wins" is natural.
- x and c share these exit statuses: 1 failure, 2 usage, 3 bad input,
4 missing dependency.
- Error carries a status; usage errors add a hint to use --help.
- Problems reports every validation error before exiting with the
status of the first, so users can fix everything in one go.
- Main turns SIGINT, SIGTERM and SIGHUP into context cancellation.
Commands can then stop their backend and clean up; the process exits
with 128 + the signal number, and a second signal kills at once.
Diagnostics are printed as "prog: message" on stderr, at three levels:
quiet (errors only), normal and verbose. Warnings and errors are
colored only when stderr is a terminal, NO_COLOR is unset and TERM is
not "dumb"; the terminal check uses the TCGETS ioctl instead of
guessing from the file mode.
Module src.panahifar.ir/ahp/archive-utils, Go 1.26. The only dependency
is golang.org/x/sys, for renameat2(2) and terminal ioctls that the
standard library does not expose.