Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

gzip

From Wikipedia, the free encyclopedia
GNU file compression/decompression tool

gzip (software)
Original authors
DeveloperGNU Project
Initial release31 October 1992; 33 years ago (1992-10-31)
Stable release
1.14[1] Edit this on Wikidata / 9 April 2025
Written inC
Operating systemUnix-like,Plan 9,Inferno
TypeData compression
LicenseGPL-3.0-or-later
Websitewww.gnu.org/software/gzip/
Repositorygit.savannah.gnu.org/cgit/gzip.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).

File format

[edit]
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 number1F 8B
Size limitationUnlimited
Developed byJean-loup Gailly and Mark Adler
Type of formatData compression
StandardIETFRFC 1952
Open format?Yes
Websitegzip.org (obsolete)

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.

gzip can be combined with thetar program to compress multiple files.

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]

File structure

[edit]

Multi-byte values uselittle-endian.[7]

Offset (bytes)Field[8]Size (bytes)Description
0ID11Magic number. Must be1F 8B.
1ID21
2CM1Compression method. Must be 8 (Deflate).
3FLG1Flags. Reserved bits must be zero.
  • Bit 0 (LSb):FTEXT. Set by the compressor to indicate the file encoding is probablyASCII.
  • Bit 1:FHCRC
  • Bit 2:FEXTRA
  • Bit 3:FNAME
  • Bit 4:FCOMMENT
  • Bit 5: Reserved
  • Bit 6: Reserved
  • Bit 7 (MSb): Reserved
4MTIME4Unix 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.
8XFL1Extra flags.
  • Deflate-specific flags.
    • 0: None (default value)
    • 2: Best compression (level 9)
    • 4: Fastest compression (level 1)
9OS1Filesystem on which compression occurred.
10XLEN0 or 2Extra 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.
12Extra field0 orXLEN
VariesFile name0 or variesNull-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 comment0 or variesNull-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.
CRC160 or 2Two 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 dataVariesDeflate stream.
CRC324CRC-32 (ISO 3309) of theuncompressed data.
ISIZE4Size (in bytes) of theuncompressed data modulo232{\displaystyle 2^{32}}.

Implementations

[edit]
NetBSD Gzip / FreeBSD Gzip
DeveloperThe NetBSD Foundation
Written inC
TypeData compression
LicenseSimplified BSD License
Repositorycvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/gzip/

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]

Damage recovery

[edit]

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]

Derivatives and other uses

[edit]

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]

See also

[edit]

Notes

[edit]
  1. ^Jim Meyering (9 April 2025)."gzip-1.14 released [stable]". Retrieved10 April 2025.
  2. ^The 'application/zlib' and 'application/gzip' Media Types. Internet Engineering Task Force.doi:10.17487/RFC6713.RFC6713. Retrieved1 March 2014.
  3. ^"GNU Gzip: Advanced usage".Gnu.org.Archived from the original on 24 December 2012. Retrieved28 November 2012.
  4. ^"Can gzip compress several files into a single archive?".Gnu.org. Archived fromthe original on 22 July 2010. Retrieved27 January 2010.
  5. ^"tarball, The Jargon File, version 4.4.7".Catb.org.Archived from the original on 20 March 2017. Retrieved27 January 2010.
  6. ^"GNU Gzip".The GNU Operating System and the Free Software Movement. 5 February 2023. Retrieved3 April 2024.gunzip can currently decompress files created by gzip, zip, compress or pack. The detection of the input format is automatic.
  7. ^Overall conventions. p. 4.doi:10.17487/RFC1952.RFC1952.
  8. ^Member format. p. 5.doi:10.17487/RFC1952.RFC1952.
  9. ^"OpenBSD gzip(1) manual page".Openbsd.org. OpenBSD. Retrieved4 February 2018.
  10. ^"gzip". Man.freebsd.org. 9 October 2011.Archived from the original on 17 December 2019. Retrieved1 March 2014.
  11. ^Mark Adler (2017)."pigz: A parallel implementation of gzip for modern multi-processor, multi-core machines".zlib.net.Archived from the original on 18 December 2018. Retrieved23 December 2018.
  12. ^Recovering a damaged .gz file – Jean-loup Gailly, GZip.org
  13. ^"How To Extract / Unzip tar.gz Files From Linux Command Line".Knowledge Base by phoenixNAP. 14 November 2019. Retrieved12 January 2022.
  14. ^Lawrence, Eric (21 November 2014)."Compressing the Web".MSDN Blogs > IEInternals.Microsoft.Archived from the original on 28 October 2015. Retrieved2 November 2015.
  15. ^"Comparison Tool: 7-zip vs bzip2 vs gzip".compressionratings.com. Archived fromthe original on 1 November 2014. Retrieved1 November 2014.
  16. ^Jiang, Zhiying; Yang, Matthew; Tsirlin, Mikhail; Tang, Raphael; Dai, Yiqin; Lin, Jimmy (July 2023).""Low-Resource" Text Classification: A Parameter-Free Classification Method with Compressors".Findings of the Association for Computational Linguistics: ACL 2023. Toronto, Canada: Association for Computational Linguistics:6810–6828.doi:10.18653/v1/2023.findings-acl.426.S2CID 260668487.

References

[edit]

External links

[edit]
Archiving only
Compressing only
Archiving
and compressing
Software packaging
and distributing
Document packaging
and distributing
Archivers with
compression
(comparison)
Free and
open-source
Freeware
Commercial
Non-archiving
compressors
Generic
For code
Audio
compression

(comparison)
Lossy
Lossless
Video
compression

(comparison)
Lossy
MPEG-4 ASP
H.264
HEVC
Others
Lossless
History
Licenses
Software
Contributors
Other topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Gzip&oldid=1338397538"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp