### Install Zstandard using Makefile Source: https://github.com/facebook/zstd/wiki/Home Install the zstd binary, library, and man page after building. Requires 'make install' to be run from the root directory. ```bash make install ``` -------------------------------- ### Basic Test Setup Script Source: https://github.com/facebook/zstd/blob/dev/tests/cli-tests/README.md A simple setup script that creates files for testing. This script is run before each test case. ```shell #!/bin/sh # Create some files for testing with datagen > file datagen > file0 datagen > file1 ``` -------------------------------- ### Example output with zlib Source: https://github.com/facebook/zstd/blob/dev/zlibWrapper/README.md This output is from the original zlib example.c file, demonstrating its standard behavior. ```text zlib version 1.2.8 = 0x1280, compile flags = 0x65 uncompress(): hello, hello! gzread(): hello, hello! gzgets() after gzseek: hello! inflate(): hello, hello! large_inflate(): OK after inflateSync(): hello, hello! inflate with dictionary: hello, hello! ``` -------------------------------- ### Install Zstandard with vcpkg Source: https://github.com/facebook/zstd/blob/dev/README.md Use vcpkg to clone the repository, bootstrap the tool, integrate it with your system, and install the zstd package. Ensure the vcpkg repository is up-to-date for the latest version. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install zstd ``` -------------------------------- ### Build and Run zstd Fuzzing Example Source: https://github.com/facebook/zstd/blob/dev/tests/fuzz/seq_prod_fuzz_example/README.md Commands to build the corpora, compile the example, and run the fuzzer with a custom sequence producer. ```bash make corpora make -C seq_prod_fuzz_example/ python3 ./fuzz.py build all --enable-fuzzer --enable-asan --enable-ubsan --cc clang --cxx clang++ --custom-seq-prod=seq_prod_fuzz_example/example_seq_prod.o python3 ./fuzz.py libfuzzer simple_round_trip ``` -------------------------------- ### Install Zstandard with Conan Source: https://github.com/facebook/zstd/blob/dev/README.md Install pre-built zstd binaries or build from source using Conan. This command requires the zstd package and will automatically build missing dependencies. ```bash conan install --requires="zstd/[*]" --build=missing ``` -------------------------------- ### Install Zstandard with Multiarch Support Source: https://github.com/facebook/zstd/blob/dev/lib/README.md Use the LIBDIR variable to specify architecture-specific directories for multiarch systems like Debian/Ubuntu. This ensures correct installation paths and pkg-config generation. ```bash # For x86_64 systems on Ubuntu/Debian: make install PREFIX=/usr LIBDIR=/usr/lib/x86_64-linux-gnu # For ARM64 systems on Ubuntu/Debian: make install PREFIX=/usr LIBDIR=/usr/lib/aarch64-linux-gnu ``` -------------------------------- ### Example output with zstd wrapper Source: https://github.com/facebook/zstd/blob/dev/zlibWrapper/README.md This output is from the modified example.c file, compiled with the zstd wrapper and -DZWRAP_USE_ZSTD=1. Note the absence of 'inflateSync' related output. ```text zlib version 1.2.8 = 0x1280, compile flags = 0x65 uncompress(): hello, hello! gzread(): hello, hello! gzgets() after gzseek: hello! inflate(): hello, hello! large_inflate(): OK inflate with dictionary: hello, hello! ``` -------------------------------- ### Dictionary Training Setup Once Script Source: https://github.com/facebook/zstd/blob/dev/tests/cli-tests/README.md This script runs once before all tests in a suite. It generates data files and trains a zstd dictionary using them. ```shell #!/bin/sh set -e mkdir files/ dicts/ for i in $(seq 10); do datagen -g1000 > files/$i done zstd --train -r files/ -o dicts/0 ``` -------------------------------- ### Dictionary Test Suite Setup Script Source: https://github.com/facebook/zstd/blob/dev/tests/cli-tests/README.md This script runs before each test case in the dictionary suite. It copies pre-built dictionaries and files from the parent directory to the test case's scratch directory. ```shell #!/bin/sh # Runs in the test case's scratch directory. # The test suite's scratch directory that # `setup_once` operates in is the parent directory. cp -r ../files ../dicts . ``` -------------------------------- ### Command-Line Interface (CLI) Usage Examples Source: https://context7.com/facebook/zstd/llms.txt Illustrates common Zstandard CLI operations, including basic compression/decompression, setting compression levels, multi-threading, dictionary usage, benchmarking, streaming, and format conversion. ```APIDOC ## Command-Line Interface (CLI) Usage The `zstd` CLI exposes the full library through a gzip-compatible interface. It supports recursive directory compression, multi-threading, benchmarking, multiple output formats, and environment-variable configuration. ```bash # Basic compression (level 3 default) — produces input.txt.zst, keeps original zstd input.txt # Decompress zstd -d input.txt.zst # Set compression level (1=fastest, 19=best; --ultra enables 20-22) zstd -9 large_file.bin zstd --ultra -20 archive.tar # Fast (negative) levels zstd --fast=4 realtime_data.bin # very fast, lower ratio # Multi-threaded compression (all available cores) zstd -T0 -9 bigfile.tar -o bigfile.tar.zst # Dictionary workflow zstd --train corpus/* -o app.dict zstd -D app.dict data/*.json zstd -d -D app.dict data/*.json.zst # Benchmark levels 1-9, minimum 5 seconds each zstd -b1 -e9 -i5 testfile.bin # Streaming from stdin / to stdout cat data.bin | zstd -c > data.bin.zst zstd -dc data.bin.zst | wc -c # Compress to gzip format (requires zlib at build time) zstd --format=gzip input.txt # produces input.txt.gz # Environment variables (override defaults without passing flags) ZSTD_CLEVEL=7 ZSTD_NBTHREADS=4 tar --zstd -cf archive.tar.zst directory/ # Integrity check zstd --test archive.tar.zst # archive.tar.zst : OK ``` ``` -------------------------------- ### Build and Run Fuzzing Harness Source: https://github.com/facebook/zstd/blob/dev/tests/fuzz/README.md Build a new fuzzing harness with specified options and then run it using libFuzzer. Ensure you have the necessary build tools and libraries installed. ```bash ./fuzz.py build your_harness --enable-fuzzer --enable-asan --enable-ubsan --cc clang --cxx clang++ ``` ```bash ./fuzz.py libfuzzer your_harness ``` -------------------------------- ### Begin Streaming Decompression Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Starts the streaming decompression process. Use `ZSTD_decompressBegin_usingDict` or `ZSTD_decompressBegin_usingDDict` if a dictionary is required. ```c size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx); ``` -------------------------------- ### Environment Variables for Configuration (CLI) Source: https://context7.com/facebook/zstd/llms.txt Overrides default compression settings using environment variables. This example sets the compression level and number of threads. ```bash ZSTD_CLEVEL=7 ZSTD_NBTHREADS=4 tar --zstd -cf archive.tar.zst directory/ ``` -------------------------------- ### Get Timing and Counter Statistics with Perf Source: https://github.com/facebook/zstd/blob/dev/CONTRIBUTING.md Quickly obtain relevant timing and counter statistics for a benchmark program using perf. ```bash perf stat -r # ``` -------------------------------- ### Compile ZSTD DLL with gcc/MinGW Source: https://github.com/facebook/zstd/blob/dev/lib/dll/example/README.md Example command to compile a C file using the ZSTD dynamic library with gcc/MinGW. Ensure header files are included and the DLL is linked. ```bash gcc $(CFLAGS) -Iinclude\ test-dll.c -o test-dll dll\libzstd.dll ``` -------------------------------- ### Configure and Build Zstandard with Meson Source: https://github.com/facebook/zstd/blob/dev/build/meson/README.md Use these commands to set up the Meson build environment, configure build options, and compile the zstandard library. Ensure you are in the `build/meson` directory before running. ```sh meson setup -Dbin_programs=true -Dbin_contrib=true builddir cd builddir ninja # to build ninja install # to install ``` ```sh DESTDIR=./staging ninja install ``` ```sh meson configure ``` -------------------------------- ### Dictionary Workflow (CLI) Source: https://context7.com/facebook/zstd/llms.txt Demonstrates the command-line workflow for training a dictionary, compressing files with it, and decompressing them. ```bash zstd --train corpus/* -o app.dict zstd -D app.dict data/*.json zstd -d -D app.dict data/*.json.zst ``` -------------------------------- ### Huffman-Coded Stream Example Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md Illustrates the byte representation of a Huffman-coded stream for the literal sequence 'ABEF'. The example shows the resulting 2-byte bitstream and an alternative representation with symbol codes separated by underscores. ```text 00010000 00001101 ``` ```text 0001_0000 00001_1_01 ``` -------------------------------- ### ZSTD_isFrame Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Checks if a given buffer starts with a valid Zstandard frame identifier. ```APIDOC ## ZSTD_isFrame ### Description Tells if the content of `buffer` starts with a valid Frame Identifier. Note: Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. Note 2: Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. Note 3: Skippable Frame Identifiers are considered valid. ### Function Signature ```c ZSTDLIB_STATIC_API unsigned ZSTD_isFrame(const void* buffer, size_t size); ``` ``` -------------------------------- ### ZSTD_isSkippableFrame Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Checks if the content of a given buffer starts with a valid Frame Identifier for a skippable frame. ```APIDOC ## ZSTD_isSkippableFrame ### Description Tells if the content of `buffer` starts with a valid Frame Identifier for a skippable frame. ### Parameters - **buffer** (const void*) - Pointer to the buffer to check. - **size** (size_t) - Size of the buffer. ### Return Value - Returns a non-zero value if the buffer starts with a skippable frame identifier, 0 otherwise. ``` -------------------------------- ### Create and Apply Zstandard Patches Source: https://github.com/facebook/zstd/wiki/Zstandard-as-a-patching-engine Use `--patch-from` to create a patch file using an old file as a dictionary, and then apply the patch using the same old file. ```bash # create the patch zstd --patch-from= -o ``` ```bash # apply the patch zstd -d --patch-from= -o ``` -------------------------------- ### Build Zstandard with Buck Source: https://github.com/facebook/zstd/blob/dev/README.md Execute this command from the repository root to build the zstd binary using Buck. The output binary will be located in the specified directory. ```bash buck build programs:zstd ``` -------------------------------- ### ZSTD_DCtx_setParameter Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Sets a single decompression parameter for a given decompression context. Parameters must be set before starting decompression. ```APIDOC ## ZSTD_DCtx_setParameter ### Description Sets a single decompression parameter for a given decompression context. Parameters must be set before starting decompression. Values outside the bounds may be clamped or trigger an error. ### Signature ```c size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value); ``` ### Parameters * `dctx` (ZSTD_DCtx*): Pointer to the decompression context. * `param` (ZSTD_dParameter): The decompression parameter to set. * `value` (int): The value to set for the parameter. ### Return Value * 0 on success, or an error code (testable with `ZSTD_isError()`). ### Notes * Valid bounds for parameters can be queried using `ZSTD_dParam_getBounds()`. ``` -------------------------------- ### Generate Multithreaded Static Library .pc File Source: https://github.com/facebook/zstd/blob/dev/lib/README.md Set the MT=1 environment variable when calling 'make install-pc' to correctly generate a .pc file for the multi-threaded static library. ```bash MT=1 make install-pc ``` -------------------------------- ### ZSTD_resetCStream Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html DEPRECATED: Resets a compression stream to start a new frame, reusing existing parameters. Use `ZSTD_CCtx_reset` and `ZSTD_CCtx_setPledgedSrcSize` instead. ```APIDOC ## ZSTD_resetCStream ### Description DEPRECATED: Resets a compression stream to start a new frame, reusing existing parameters. Use `ZSTD_CCtx_reset` and `ZSTD_CCtx_setPledgedSrcSize` instead. ### Parameters - `zcs` (ZSTD_CStream*): Pointer to the compression stream structure. - `pledgedSrcSize` (unsigned long long): The total size of the source data, or `ZSTD_CONTENTSIZE_UNKNOWN` if unknown. ### Notes - This function is deprecated and will generate compilation warnings. - `zcs` must have been initialized at least once before calling this function. - This is useful for skipping dictionary loading as it reuses the existing dictionary. - `ZSTD_resetCStream()` interprets `pledgedSrcSize == 0` as `ZSTD_CONTENTSIZE_UNKNOWN`, but `ZSTD_CCtx_setPledgedSrcSize()` does not, so `ZSTD_CONTENTSIZE_UNKNOWN` must be explicitly specified when needed. ``` -------------------------------- ### PZstandard Help Command Source: https://github.com/facebook/zstd/blob/dev/contrib/pzstd/README.md Displays the help message for PZstandard, listing all available options and configurations. This is useful for understanding advanced usage and default settings. ```bash pzstd --help ``` -------------------------------- ### ZSTD_CCtx_setParameter Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Sets a specific compression parameter for a given compression context. Parameters can be set before compression starts, with some exceptions for multi-threaded compression. ```APIDOC ## ZSTD_CCtx_setParameter ### Description Sets a specific compression parameter for a given compression context. Parameters can be set before compression starts, with some exceptions for multi-threaded compression. ### Method ZSTD_CCtx_setParameter ### Parameters #### Path Parameters - **cctx** (ZSTD_CCtx*) - Pointer to the compression context. - **param** (ZSTD_cParameter) - The compression parameter to set. - **value** (int) - The value to set for the parameter. ### Return Value - **size_t** - 0 on success, or an error code (testable with ZSTD_isError()). ``` -------------------------------- ### Get Block Size (ZSTD_getBlockSize) Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Retrieves the maximum block size that can be handled by the ZSTD_CCtx. This function is part of the deprecated block API. ```c ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.") ZSTDLIB_STATIC_API size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx); ``` -------------------------------- ### Compile and Generate Zstandard Manual Source: https://github.com/facebook/zstd/blob/dev/contrib/gen_html/README.md Demonstrates the steps to compile the gen_html program using make and then execute it to generate the zstd manual. ```bash make ./gen_html.exe 1.1.1 ../../lib/zstd.h zstd_manual.html ``` -------------------------------- ### Build Zstandard using Makefile Source: https://github.com/facebook/zstd/wiki/Home Build the zstd binary by running 'make' in the root directory. This is suitable for systems with a standard make binary. ```bash make ``` -------------------------------- ### Parameter Retrieval and Adjustment Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Functions to get and adjust compression parameters based on compression level, source size, and dictionary size. ```APIDOC ## Parameter Retrieval and Adjustment ### ZSTD_getCParams **Description**: Retrieves `ZSTD_compressionParameters` for a given compression level, estimated source size, and dictionary size. **Parameters**: - `compressionLevel` (int): The desired compression level. - `estimatedSrcSize` (unsigned long long): Estimated size of the source data (0 if unknown). - `dictSize` (size_t): Size of the dictionary (0 if no dictionary). **Return**: A `ZSTD_compressionParameters` structure. ``` ```APIDOC ### ZSTD_getParams **Description**: Similar to `ZSTD_getCParams`, but returns a full `ZSTD_parameters` object with default frame parameters. **Parameters**: - `compressionLevel` (int): The desired compression level. - `estimatedSrcSize` (unsigned long long): Estimated size of the source data (0 if unknown). - `dictSize` (size_t): Size of the dictionary (0 if no dictionary). **Return**: A `ZSTD_parameters` structure. ``` ```APIDOC ### ZSTD_checkCParams **Description**: Checks if the provided `ZSTD_compressionParameters` are within the authorized range. **Parameters**: - `params` (ZSTD_compressionParameters): The compression parameters to check. **Return**: 0 on success, or an error code. ``` ```APIDOC ### ZSTD_adjustCParams **Description**: Optimizes compression parameters for a given source size and dictionary size. Clamps parameters within the valid range. **Parameters**: - `cPar` (ZSTD_compressionParameters): The initial compression parameters. - `srcSize` (unsigned long long): The source size (use ZSTD_CONTENTSIZE_UNKNOWN if unknown). - `dictSize` (size_t): The dictionary size (0 if no dictionary). **Return**: An adjusted `ZSTD_compressionParameters` structure. This function never fails. ``` -------------------------------- ### Get Full Zstd Parameters Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Returns a full ZSTD_parameters object, similar to ZSTD_getCParams, but includes frame parameters set to defaults. ```c ZSTD_getParams ``` -------------------------------- ### Build with VS 2013 (Release Win32/x64) Source: https://github.com/facebook/zstd/blob/dev/build/VS_scripts/README.md Use this command to build both Release Win32 and Release x64 versions with Visual Studio 2013. The output will be in the corresponding bin\Release\{ARCH}\ folder. ```batch build.VS2013.cmd ``` -------------------------------- ### Build with VS 2015 (Release Win32/x64) Source: https://github.com/facebook/zstd/blob/dev/build/VS_scripts/README.md Execute this command to build both Release Win32 and Release x64 versions using Visual Studio 2015. The compiled artifacts will be located in the respective bin\Release\{ARCH}\ directories. ```batch build.VS2015.cmd ``` -------------------------------- ### Failing Test: Exit Code 1 Source: https://github.com/facebook/zstd/blob/dev/tests/cli-tests/README.md This is an example of a failing test where the script exits with code 1, but the expected exit code is 0. ```shell #!/bin/sh exit 1 ``` -------------------------------- ### Benchmark Compression Levels (CLI) Source: https://context7.com/facebook/zstd/llms.txt Benchmarks compression levels from 1 to 9, running each for a minimum of 5 seconds. ```bash zstd -b1 -e9 -i5 testfile.bin ``` -------------------------------- ### Get Next Source Size to Decompress Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Informs how many bytes are needed for the next call to `ZSTD_decompressContinue`. This exact amount must be provided. ```c size_t ZSTD_nextSrcSizeToDecompress(const ZSTD_DCtx* dctx); ``` -------------------------------- ### Basic PZstandard Usage Source: https://github.com/facebook/zstd/blob/dev/contrib/pzstd/README.md Demonstrates basic compression and decompression using PZstandard with specified input, output, and thread count. Use '-#' for compression and '-d' for decompression. ```bash pzstd input-file -o output-file -p num-threads -# # Compression ``` ```bash pzstd -d input-file -o output-file -p num-threads # Decompression ``` -------------------------------- ### Get Zstandard Version Number (C) Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Retrieves the runtime library version as a numerical value (MAJOR*10000 + MINOR*100 + RELEASE). ```c unsigned ZSTD_versionNumber(void); ``` -------------------------------- ### Train Zstandard Dictionary Source: https://github.com/facebook/zstd/wiki/Home Use this command to create a dictionary for compression. Provide a path to a set of files for training. ```bash zstd --train FullPathToTrainingSet/* -o dictionaryName ``` -------------------------------- ### PZstandard Test Execution Source: https://github.com/facebook/zstd/blob/dev/contrib/pzstd/README.md Instructions for running tests for PZstandard, which require the gtest framework. Ensure gtest is installed or built using 'make googletest'. ```bash make tests && make check ``` -------------------------------- ### Get Zstd Compression Parameters Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Retrieves the ZSTD_compressionParameters structure for a given compression level and estimated source size. Use 0 for estimatedSrcSize if unknown. ```c ZSTD_getCParams ``` -------------------------------- ### Basic Compression and Decompression (CLI) Source: https://context7.com/facebook/zstd/llms.txt Performs basic compression of a file, creating a .zst archive, and then decompresses it back to the original. ```bash zstd input.txt zstd -d input.txt.zst ``` -------------------------------- ### Get Zstandard Context/Stream Memory Usage Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html These functions return the current memory usage of Zstandard objects. Note that memory usage can change over time. ```c size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs); size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); ``` -------------------------------- ### Run Static Analysis with make Source: https://github.com/facebook/zstd/blob/dev/CONTRIBUTING.md Execute the full static analysis suite using the project's make target. This ensures all static analysis tests pass locally before submitting changes. ```bash make staticAnalyze ``` -------------------------------- ### Configure and Build zstd with CMake Source: https://github.com/facebook/zstd/blob/dev/build/cmake/README.md Use these commands to configure and build the project from the repository root. This is the recommended modern workflow. ```sh cmake -S . -B build-cmake cmake --build build-cmake ``` -------------------------------- ### Get Zstandard Version String (C) Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Retrieves the runtime library version as a human-readable string (e.g., "1.4.5"). Requires v1.3.0+. ```c const char* ZSTD_versionString(void); ``` -------------------------------- ### Run Zstandard Speed Test Script Source: https://github.com/facebook/zstd/blob/dev/tests/README.md This script automates Zstandard speed benchmarking across different commits. It clones the repository, compiles branches, and benchmarks compression/decompression speeds. Warnings are sent via email if speeds drop below a specified limit. ```bash ./test-zstd-speed.py "silesia.tar calgary.tar" "email@gmail.com" --message "tested on my laptop" --sleepTime 60 ``` ```bash nohup ./test-zstd-speed.py testFileNames emails & ``` -------------------------------- ### ZSTD_findFrameCompressedSize Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Finds the compressed size of the first ZSTD frame starting at the given source pointer. This size is suitable for use with decompression functions like ZSTD_decompress. ```APIDOC ## ZSTD_findFrameCompressedSize ### Description Finds the compressed size of the first ZSTD frame starting at the given source pointer. This size is suitable for use with decompression functions like ZSTD_decompress. It can also work with Skippable Frames. ### Function Signature `size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize);` ### Parameters * `src` (const void *) - Pointer to the start of a ZSTD frame or skippable frame. * `srcSize` (size_t) - Must be greater than or equal to the first frame's size. ### Return Value * The compressed size of the first frame (size_t). * An error code if the input is invalid. ### Notes * This method may need to scan through the frame's content to reach its end, hence the `find_` prefix. * For Skippable Frames, it returns the size of the complete skippable frame (content size + 8 bytes for headers). ``` -------------------------------- ### Zstandard CLI Help Options Source: https://github.com/facebook/zstd/blob/dev/programs/README.md Use -h or -H to display short or full usage information for the Zstandard command-line interface. This is useful for understanding available commands and options. ```bash *** Zstandard CLI (64-bit) v1.5.6, by Yann Collet *** Compress or decompress the INPUT file(s); reads from STDIN if INPUT is `-` or not provided. Usage: zstd [OPTIONS...] [INPUT... | -] [-o OUTPUT] Options: -o OUTPUT Write output to a single file, OUTPUT. -k, --keep Preserve INPUT file(s). [Default] --rm Remove INPUT file(s) after successful (de)compression to file. -# Desired compression level, where `#` is a number between 1 and 19; lower numbers provide faster compression, higher numbers yield better compression ratios. [Default: 3] -d, --decompress Perform decompression. -D DICT Use DICT as the dictionary for compression or decompression. -f, --force Disable input and output checks. Allows overwriting existing files, receiving input from the console, printing output to STDOUT, and operating on links, block devices, etc. Unrecognized formats will be passed-through through as-is. -h Display short usage and exit. -H, --help Display full help and exit. -V, --version Display the program version and exit. Advanced options: -c, --stdout Write to STDOUT (even if it is a console) and keep the INPUT file(s). -v, --verbose Enable verbose output; pass multiple times to increase verbosity. -q, --quiet Suppress warnings; pass twice to suppress errors. --trace LOG Log tracing information to LOG. --[no-]progress Forcibly show/hide the progress counter. NOTE: Any (de)compressed output to terminal will mix with progress counter text. -r Operate recursively on directories. --filelist LIST Read a list of files to operate on from LIST. --output-dir-flat DIR Store processed files in DIR. --output-dir-mirror DIR Store processed files in DIR, respecting original directory structure. --[no-]asyncio Use asynchronous IO. [Default: Enabled] --[no-]check Add XXH64 integrity checksums during compression. [Default: Add, Validate] If `-d` is present, ignore/validate checksums during decompression. -- Treat remaining arguments after `--` as files. Advanced compression options: --ultra Enable levels beyond 19, up to 22; requires more memory. --fast[=#] Use to very fast compression levels. [Default: 1] --adapt Dynamically adapt compression level to I/O conditions. --long[=#] Enable long distance matching with window log #. [Default: 27] --patch-from=REF Use REF as the reference point for Zstandard's diff engine. -T# Spawn # compression threads. [Default: 1; pass 0 for core count.] --single-thread Share a single thread for I/O and compression (slightly different than `-T1`). --auto-threads={physical|logical} Use physical/logical cores when using `-T0`. [Default: Physical] -B# Set job size to #. [Default: 0 (automatic)] --rsyncable Compress using a rsync-friendly method (`-B` sets block size). --exclude-compressed Only compress files that are not already compressed. --stream-size=# Specify size of streaming input from STDIN. --size-hint=# Optimize compression parameters for streaming input of approximately size #. --target-compressed-block-size=# Generate compressed blocks of approximately # size. --no-dictID Don't write `dictID` into the header (dictionary compression only). --[no-]compress-literals Force (un)compressed literals. --[no-]row-match-finder Explicitly enable/disable the fast, row-based matchfinder for the 'greedy', 'lazy', and 'lazy2' strategies. --format=zstd Compress files to the `.zst` format. [Default] --[no-]mmap-dict Memory-map dictionary file rather than mallocing and loading all at once --format=gzip Compress files to the `.gz` format. --format=xz Compress files to the `.xz` format. --format=lzma Compress files to the `.lzma` format. --format=lz4 Compress files to the `.lz4` format. Advanced decompression options: ``` -------------------------------- ### Build Zstandard and Regression Test Binaries Source: https://github.com/facebook/zstd/blob/dev/tests/regression/README.md Builds the main zstd binary and the regression test executable. Ensure you are in the root of the zstd repository before running. ```bash # Build the zstd binary make clean make -j zstd # Build the regression test binary cd tests/regression make clean make -j test ``` -------------------------------- ### Resetting ZSTD_CStream for New Session Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Resets a ZSTD_CStream for a new session, clearing any previously set dictionary. Use this when starting a new compression task with the same stream object. ```c ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only); ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any) ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel); ``` -------------------------------- ### Get Obsolete Decompressed Size Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html ZSTD_getDecompressedSize is an obsolete function that returns the decompressed size if known and not empty, otherwise 0. It is replaced by ZSTD_getFrameContentSize for more specific error handling. ```c ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize") unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize); ``` -------------------------------- ### Build Zstandard with Multithreading Enabled Source: https://github.com/facebook/zstd/blob/dev/lib/README.md Force enable multithreading on both dynamic and static libraries by appending '-mt' to the target. The generated .pc file will include required Libs and Cflags. ```bash make lib-mt ``` -------------------------------- ### Build Fat (Universal2) Zstandard with CMake and Ninja Source: https://github.com/facebook/zstd/blob/dev/README.md Build Zstandard with support for both Apple Silicon and Intel architectures using CMake and Ninja. This command configures the build for Universal2 output. ```bash cmake -S . -B build-cmake-debug -G Ninja -DCMAKE_OSX_ARCHITECTURES="x86_64;x86_64h;arm64" cd build-cmake-debug ninja sudo ninja install ``` -------------------------------- ### Embedding zstd wrapper in a zlib project Source: https://github.com/facebook/zstd/blob/dev/zlibWrapper/README.md To embed the zstd wrapper, change zlib includes to zstd_zlibwrapper.h and adjust compilation flags. This example shows the modified linking command. ```bash gcc project.o zstd_zlibwrapper.o gz*.c -lz -lzstd ``` -------------------------------- ### Build with VS 2015 (Release x64 using v120) Source: https://github.com/facebook/zstd/blob/dev/build/VS_scripts/README.md This command builds the Release x64 version using Visual Studio 2015, compatible with msvcr120.dll. The output is located in bin\Release\x64\. ```batch build.generic.cmd VS2015 x64 Release v120 ``` -------------------------------- ### Get Minimum Decoding Buffer Size (ZSTD_decodingBufferSize_min) Source: https://github.com/facebook/zstd/blob/dev/doc/zstd_manual.html Calculates the minimum buffer size required for decoding when the frame content size is unknown. Pass ZSTD_CONTENTSIZE_UNKNOWN for frameContentSize in this case. ```c size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize); ```