@ 49bf1d14raw
current

zstd(1) – zstd, zstdmt, unzstd, zstdcat - Compress or decompress .zst files

SYNOPSIS

zstd [] [-|] [-o ]

zstdmt is equivalent to zstd -T0

unzstd is equivalent to zstd -d

zstdcat is equivalent to zstd -dcf

DESCRIPTION

zstd is a fast lossless compression algorithm and data compression tool, with command line syntax similar to gzip(1) and xz(1). It is based on the LZ77 family, with further FSE & huff0 entropy stages. zstd offers highly configurable compression speed, from fast modes at > 200 MB/s per core, to strong modes with excellent compression ratios. It also features a very fast decoder, with speeds > 500 MB/s per core, which remains roughly stable at all compression settings.

zstd command line syntax is generally similar to gzip, but features the following few differences:

zstd processes each file according to the selected operation mode. If no files are given or file is -, zstd reads from standard input and writes the processed data to standard output. zstd will refuse to write compressed data to standard output if it is a terminal: it will display an error message and skip the file. Similarly, zstd will refuse to read compressed data from standard input if it is a terminal.

Unless --stdout or -o is specified, files are written to a new file whose name is derived from the source file name:

Concatenation with .zst Files

It is possible to concatenate multiple .zst files. zstd will decompress such agglomerated file as if it was a single .zst file.

OPTIONS

Integer Suffixes and Special Values

In most places where an integer argument is expected, an optional suffix is supported to easily indicate large integers. There must be no space between the integer and the suffix.

Operation Mode

If multiple operation mode options are given, the last one takes effect.

Operation Modifiers

gzip Operation Modifiers

When invoked via a gzip symlink, zstd will support further options that intend to mimic the gzip behavior:

Environment Variables

Employing environment variables to set parameters has security implications. Therefore, this avenue is intentionally limited. Only ZSTD_CLEVEL and ZSTD_NBTHREADS are currently supported. They set the default compression level and number of threads to use during compression, respectively.

ZSTD_CLEVEL can be used to set the level between 1 and 19 (the “normal” range). If the value of ZSTD_CLEVEL is not a valid integer, it will be ignored with a warning message. ZSTD_CLEVEL just replaces the default compression level (3).

ZSTD_NBTHREADS can be used to set the number of threads zstd will attempt to use during compression. If the value of ZSTD_NBTHREADS is not a valid unsigned integer, it will be ignored with a warning message. ZSTD_NBTHREADS has a default value of max(1, min(4, nbCores/4)), and is capped at ZSTDMT_NBWORKERS_MAX==200. zstd must be compiled with multithread support for this variable to have any effect.

They can both be overridden by corresponding command line arguments: -# for compression level and -T# for number of compression threads.

ADVANCED COMPRESSION OPTIONS

zstd provides 22 predefined regular compression levels plus the fast levels. A compression level is translated internally into multiple advanced parameters that control the behavior of the compressor (one can observe the result of this translation with --show-default-cparams). These advanced parameters can be overridden using advanced compression options.

–zstd[=options]:

The options are provided as a comma-separated list. You may specify only the options you want to change and the rest will be taken from the selected or default compression level. The list of available options:

Example

The following parameters sets advanced compression options to something similar to predefined level 19 for files bigger than 256 KB:

--zstd=wlog=23,clog=23,hlog=22,slog=6,mml=3,tlen=48,strat=6

–jobsize=#:

Specify the size of each compression job. This parameter is only meaningful when multi-threading is enabled. Each compression job is run in parallel, so this value can indirectly impact the nb of active threads. Default job size varies depending on compression level (generally 4 * windowSize). --jobsize=# makes it possible to manually select a custom size. Note that job size must respect a minimum value which is enforced transparently. This minimum is either 512 KB, or overlapSize, whichever is largest. Different job sizes will lead to non-identical compressed frames.

DICTIONARY BUILDER

zstd offers dictionary compression, which greatly improves efficiency on small files and messages. It’s possible to train zstd with a set of samples, the result of which is saved into a file called a dictionary. Then, during compression and decompression, reference the same dictionary, using command -D dictionaryFileName. Compression of small files similar to the sample set will be greatly improved.

BENCHMARK

The zstd CLI provides a benchmarking mode that can be used to easily find suitable compression parameters, or alternatively to benchmark a computer’s performance. zstd -b [FILE(s)] will benchmark zstd for both compression and decompression using default compression level. Note that results are very dependent on the content being compressed.

It’s possible to pass multiple files to the benchmark, and even a directory with -r DIRECTORY. When no FILE is provided, the benchmark will use a procedurally generated lorem ipsum text.

Benchmarking will employ max(1, min(4, nbCores/4)) worker threads by default in order to match the behavior of the normal CLI I/O.

Beyond compression levels, benchmarking is also compatible with other parameters, such as number of threads (-T#), advanced compression parameters (--zstd=###), dictionary compression (-D dictionary), or even disabling checksum verification for example.

Output Format: CompressionLevel#Filename: InputSize -> OutputSize (CompressionRatio), CompressionSpeed, DecompressionSpeed

Methodology: For speed measurement, the entire input is compressed/decompressed in-memory to measure speed. A run lasts at least 1 sec, so when files are small, they are compressed/decompressed several times per run, in order to improve measurement accuracy.

SEE ALSO

zstdgrep(1), zstdless(1), gzip(1), xz(1)

The format is specified in Y. Collet, “Zstandard Compression and the ‘application/zstd’ Media Type”, https://www.ietf.org/rfc/rfc8878.txt, Internet RFC 8878 (February 2021).

BUGS

Report bugs at: https://github.com/facebook/zstd/issues

AUTHOR

Yann Collet