LinuxCommandLibrary

zlib-flate

Compress or decompress data using zlib

TLDR

Compress a file

$ zlib-flate -compress < [path/to/input_file] > [path/to/compressed.zlib]
copy

Uncompress a file
$ zlib-flate -uncompress < [path/to/compressed.zlib] > [path/to/output_file]
copy

Compress a file with a specified compression level. 0=Fastest (Worst), 9=Slowest (Best)
$ zlib-flate -compress=[compression_level] < [path/to/input_file] > [path/to/compressed.zlib]
copy

SYNOPSIS

zlib-flate [-compress | -decompress] [-level=level] [-raw] [input-file [output-file]]

Choose either -compress or -decompress mode. Input and output files are optional; if not provided, the command operates on stdin and stdout.

PARAMETERS

-compress
    Sets the operation mode to compress the input data using the zlib DEFLATE algorithm.

-decompress
    Sets the operation mode to decompress the input data that was previously compressed with the zlib DEFLATE algorithm.

-level=level
    Specifies the compression level, where 'level' is an integer from 1 (fastest compression) to 9 (best compression). This option is only applicable when using -compress.

-raw
    Uses raw DEFLATE/INFLATE without the zlib header and checksum. This is useful for handling raw deflate streams, which are sometimes found in non-standard or specific contexts (e.g., certain PDF streams).

input-file
    The path to the file from which data will be read. If omitted, data is read from standard input (stdin).

output-file
    The path to the file where the processed data will be written. If omitted, data is written to standard output (stdout).

DESCRIPTION

The zlib-flate command is a utility designed to perform compression and decompression of data using the zlib format, which employs the DEFLATE compression algorithm. It is often distributed as part of the qpdf library suite, which focuses on PDF transformation and inspection.

This tool is particularly useful for handling data streams that have been compressed with zlib, such as FlateDecode streams found within PDF documents. It operates by reading input data from standard input (stdin) or a specified input file, applying either compression or decompression, and then writing the resulting output to standard output (stdout) or a specified output file.

zlib-flate provides a command-line interface to the underlying zlib library functions, making it a convenient tool for developers, system administrators, and anyone needing to interact with zlib-compressed data outside of a programming environment.

CAVEATS

zlib-flate is typically not a standalone utility installed globally by default on most Linux distributions. It is commonly bundled as a helper application with other software packages, most notably qpdf.

Users might need to install qpdf or similar packages to gain access to zlib-flate. Its primary purpose is to interact with zlib streams, not general file compression like gzip or bzip2, which handle different formats and have more advanced features for file archiving.

INPUT/OUTPUT BEHAVIOR

By default, zlib-flate reads binary data from standard input (stdin) and writes binary data to standard output (stdout). This makes it suitable for piping with other commands in a Linux shell environment. When input-file or output-file arguments are provided, it operates directly on those files.

RELATIONSHIP TO ZLIB LIBRARY

zlib-flate is essentially a command-line wrapper for the zlib compression library. The zlib library implements the DEFLATE compression algorithm (used in gzip and PKZIP) and is widely used for data compression in various applications and network protocols. zlib-flate provides direct access to these low-level compression/decompression capabilities without the overhead of file archiving metadata often found in tools like gzip.

HISTORY

The zlib-flate utility emerged as part of the qpdf project, a powerful command-line tool and C++ library for transforming and inspecting PDF files. Its inclusion in qpdf was driven by the necessity to handle FlateDecode compressed streams, a common compression method used within PDF documents, directly from the command line.

While the underlying zlib compression library itself has a long and established history, dating back to 1995, zlib-flate provides a convenient interface to its core DEFLATE/INFLATE functionalities without requiring custom programming. Its development has mirrored the needs of PDF manipulation and general zlib stream processing.

SEE ALSO

qpdf(1), gzip(1), zlib(3)

Copied to clipboard