| gzip (software) | |
|---|---|
| Original authors | |
| Developer | GNU Project |
| Initial release | 31 October 1992; 33 years ago (1992-10-31) |
| Stable release | 1.14[1] |
| Written in | C |
| Operating system | Unix-like,Plan 9,Inferno |
| Type | Data compression |
| License | GPL-3.0-or-later |
| Website | www |
| Repository | git |
gzip is afile format and asoftware application for filecompression and decompression. The program was created byJean-loup Gailly andMark Adler as afree software replacement for thecompress program used in earlyUnix systems, and intended for use byGNU (from which the "g" of gzip is derived). Version 0.1 was first publicly released on 31 October 1992, and version 1.0 followed in February 1993.
As the file format can be decompressed via astreaming algorithm, it is commonly used in stream-based technology such asWeb protocols,data interchange andETL (instandard pipes).
| gzip (file format) | |
|---|---|
| Filename extension | .gz,.tgz,.gzip |
| Internet media type | application/gzip[2] |
| Uniform Type Identifier (UTI) | org.gnu.gnu-zip-archive,org.gnu.gnu-zip-tar-archive |
| Magic number | 1F 8B |
| Size limitation | Unlimited |
| Developed by | Jean-loup Gailly and Mark Adler |
| Type of format | Data compression |
| Standard | IETFRFC 1952 |
| Open format? | Yes |
| Website | gzip |
A gzip file (described in the table below) contains a 10-byteheader, optional extra header fields,DEFLATE-compressed data, and an 8-bytetrailer.
gzip is based on the DEFLATE algorithm, which is a combination ofLZ77 andHuffman coding. DEFLATE was intended as a replacement forLZW and otherpatent-encumbereddata compressionalgorithms which, at the time, limited the usability of thecompress utility and other popular archivers.

Although multiple streams may beconcatenated (gzipped files are simply decompressed concatenated as if they were originally one file),[3] normally only a single file is compressed.[4] Compressed archives are typically created by assembling collections of files into a singletar archive (also calledtarball),[5] and then compressing that archive with gzip. The final compressed file usually has the extension.tar.gz ,.tgz or.gzip
gzip is not to be confused with theZIP archive format, which also usesDEFLATE. The ZIP format can hold collections of files without an external archiver, but is less compact than compressedtarballs holding the same data, because it compresses files individually and cannot take advantage of redundancy between files (solid compression).The gzip file format is also not to be confused with that of the compress utility, based on LZW, with extension.Z; however, the gunzip utility is able to decompress.Z files.[6]
Multi-byte values uselittle-endian.[7]
| Offset (bytes) | Field[8] | Size (bytes) | Description |
|---|---|---|---|
| 0 | ID1 | 1 | Magic number. Must be1F 8B. |
| 1 | ID2 | 1 | |
| 2 | CM | 1 | Compression method. Must be 8 (Deflate). |
| 3 | FLG | 1 | Flags. Reserved bits must be zero. |
| 4 | MTIME | 4 | Unix time when the file waslast modified. If the compressed data did not come from a file,MTIME is the Unix timewhen compression started. 0 means notimestamp is available. |
| 8 | XFL | 1 | Extra flags.
|
| 9 | OS | 1 | Filesystem on which compression occurred. |
| 10 | XLEN | 0 or 2 | Extra field is a sequence of subfields.XLEN is the size in bytes of the extra field. Both are present if theFEXTRA flag is set. Each subfield starts withSI1 SI2 (a two-byte identifier; typically two ASCII letters with somemnemonic value) followed by a two-byteLEN value indicating the remaining number of bytes in the subfield. Subfield IDs withSI2 = 0 are reserved for future use. |
| 12 | Extra field | 0 orXLEN | |
| Varies | File name | 0 or varies | Null-terminatedname of the file being compressed. Present if theFNAME flag is set. Encoded asISO 8859-1 (latin-1). Converted tolowercase oncase-insensitive filesystems. Empty if the compressed data did not come from a named file. |
| File comment | 0 or varies | Null-terminatedfile comment intended for human consumption. Present if theFCOMMENT flag is set. Encoded as ISO 8859-1 (latin-1).Newlines should use a single line feed (LF) character. | |
| CRC16 | 0 or 2 | Two least significant bytes of theCRC-32 (ISO 3309) of all bytes in the gzip file up to (not including) this field. Present if theFHCRC flag is set. | |
| Compressed data | Varies | Deflate stream. | |
| CRC32 | 4 | CRC-32 (ISO 3309) of theuncompressed data. | |
| ISIZE | 4 | Size (in bytes) of theuncompressed data modulo. |
| NetBSD Gzip / FreeBSD Gzip | |
|---|---|
| Developer | The NetBSD Foundation |
| Written in | C |
| Type | Data compression |
| License | Simplified BSD License |
| Repository | cvsweb |
Various implementations of the program have been written. The most commonly known is the GNU Project's implementation usingLempel-Ziv coding (LZ77).OpenBSD's version of gzip is actually thecompress program, to which support for the gzip format was added in OpenBSD 3.4. The "g" in this specific version stands forgratis.[9]FreeBSD,DragonFly BSD andNetBSD use a BSD-licensed implementation instead of the GNU version; it is actually acommand-line interface forzlib intended to be compatible with the GNU implementations' options.[10] These implementations originally come fromNetBSD, and support decompression ofbzip2 and the Unixpack format.
An alternative compression program achieving 3-8% better compression isZopfli. It achieves gzip-compatible compression using more exhaustive algorithms, at the expense of compression time required. It does not affect decompression time.
pigz, written by Mark Adler, is compatible with gzip and speeds up compression by using all available CPU cores and threads.[11]
Data in blocks prior to the first damaged part of the archive is usually fully readable. Data from blocks not demolished by damage that are located afterwardmay berecoverable through difficult workarounds.[12]
Thetar utility included in most Linux distributions can extract .tar.gz files by passing thez option, e.g.,tar -zxf file.tar.gz, where-z instructs decompression,-x means extraction, and-f specifies the name of the compressed archive file to extract from. Optionally,-v (verbose) lists files as they are being extracted.[13]
Thezlib library implements the DEFLATE algorithm, and supports both the gzip file format and a lightweightdata stream format. The zlib stream format, DEFLATE, and the gzip file format were standardized respectively as RFC 1950, RFC 1951, and RFC 1952.
The gzip format is used inHTTP compression, a technique used to speed up the sending ofHTML and other content on theWorld Wide Web. It is one of the three standard formats for HTTP compression as specified in RFC 2616. ThisRFC also specifies a zlib format (called "DEFLATE"), which is equal to the gzip format except that gzip adds eleven bytes of overhead in the form of headers and trailers. Still, the gzip format is sometimes recommended over zlib becauseInternet Explorer does not implement the standard correctly and cannot handle the zlib format as specified in RFC 1950.[14]
zlib DEFLATE is used internally by thePortable Network Graphics (PNG) format.
Since the late 1990s,bzip2, a file compression utility based on a block-sorting algorithm, has gained some popularity as a gzip replacement. It produces considerably smaller files (especially for source code and other structured text), but at the cost of memory and processing time (up to a factor of 4).[15]
AdvanceCOMP,Zopfli, libdeflate and7-Zip can produce gzip-compatible files, using an internal DEFLATE implementation with better compression ratios than gzip itself—at the cost of more processor time compared to the reference implementation.[citation needed]
Research published in 2023 showed that simple lossless compression techniques such as gzip could be combined with ak-nearest-neighbor classifier to create an attractive alternative todeep neural networks for text classification innatural language processing. This approach has been shown to equal and in some cases outperform conventional approaches such asBERT due to low resource requirements, e.g. no requirement forGPU hardware.[16]
gunzip can currently decompress files created by gzip, zip, compress or pack. The detection of the input format is automatic.