Skip to content

cli: support --list for gzip files - #4713

Open
RachitJava wants to merge 1 commit into
facebook:devfrom
RachitJava:list-gzip-files
Open

cli: support --list for gzip files#4713
RachitJava wants to merge 1 commit into
facebook:devfrom
RachitJava:list-gzip-files

Conversation

@RachitJava

Copy link
Copy Markdown

Fixes #3037

zstd -l on a gzip file previously failed with File "..." not compressed by zstd, which is a gap in gzip drop-in compatibility when zstd is used through a gzip symlink. Per the discussion in #3037, -l support for gzip files is the only remaining request in that issue.

What this does

The --list command now recognizes gzip files: it parses the gzip header (including the optional FEXTRA, FNAME, FCOMMENT and FHCRC fields), then reads the CRC32 and the decompressed size (ISIZE) from the trailer. No decompression is performed and no zlib is required, so this works in all build configurations — verified with HAVE_ZLIB=0 HAVE_LZMA=0 HAVE_LZ4=0.

$ zstd -l sample.txt.gz sample.txt.zst
Frames  Skips  Compressed  Uncompressed  Ratio  Check  Filename
     1      0      48   B        38   B  0.792  CRC32  sample.txt.gz
     1      0      33   B        38   B  1.152  XXH64  sample.txt.zst

The verbose view (-lv) prints a gzip-specific summary (format, sizes, ratio, CRC32) instead of the zstd-specific fields (frames, dict ID, window size), and the totals row reports CRC32 when all listed files are gzip.

Semantics

Same as gzip -l: the decompressed size comes from the trailer, so it is modulo 2^32 and accounts only for the last stream of a multi-stream file. This limitation is documented in the man page entry for -l. Malformed inputs (truncated files, reserved header flags, unknown compression methods) are rejected with an error, and files that are neither zstd nor gzip fail with the same message as before.

Tests

Added tests/cli-tests/list/list-gzip.sh with a deterministic embedded gzip fixture, covering the default and verbose listings, multi-file totals, the not-compressed error path, and truncated input. The full cli-tests suite passes (45/45). Also compared the output against gzip -l on the same files, including a concatenated multi-stream file and a file using FHCRC.

zstd -l on a gzip file previously failed with "File not compressed by
zstd", which is a gap in gzip drop-in compatibility when zstd is used
through a gzip symlink (facebook#3037).

Teach the --list command to recognize gzip files: parse the gzip header
(including the optional FEXTRA, FNAME, FCOMMENT and FHCRC fields), then
read the CRC32 checksum and the decompressed size from the trailer.
No decompression is performed, and no zlib support is required, so this
works in all build configurations. As with gzip -l, the reported
decompressed size is modulo 2^32 and accounts only for the last stream
of a multi-stream file; this limitation is documented in the man page.

The Check column reports CRC32 for gzip files, and the verbose view
displays a gzip-specific summary. Files that are neither zstd nor gzip
are still rejected as before.

Fixes facebook#3037
@meta-cla meta-cla Bot added the CLA Signed label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

better gzip(1) command line option compatibility: Support -l for gzip files

1 participant