GZIP (.gz)

Single-stream Deflate compression format.

Overview

A gzip member has a 10-byte header (magic 1F 8B, method, flags, mtime, extra flags, OS) with optional extra field, name, comment and header CRC, followed by a Deflate stream and a trailer of CRC-32 and the uncompressed size modulo 232. Members may be concatenated.

Where it is used

  • Web content encoding and compressed tarballs (.tar.gz).
  • Log rotation and backups.

History

  • Written by Jean-loup Gailly and Mark Adler in 1992; specified in RFC 1952.

Status today

  • Universal and actively used.

Structures read by the implementation

Offsets are in bytes from the start of the buffer named in each heading. Field names are taken from the implementation and are not an official specification. Fixed-width integers are shown as u/i (unsigned/signed) followed by bit width and byte order.

MemberHeader.Carve buffer trailer · GzipCarver.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x44u32 LE–

MemberHeader.ReadHeader buffer header · GzipCarver.cs

OffsetSizeTypeFieldNotes
0x01u8–
0x11u8–
0x21u8–
0x31u8–
0x31u8Flags
0x44u32 LETime
0x81u8Null
0x91u8Null

Constants

General InflateDecoder

NameValueTypeNotes
OutputChunk65536int
FastBits10int
LengthBase[3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 1…ushort[]
LengthExtra[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]byte[]
DistanceBase[1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1…ushort[]
DistanceExtra[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, …byte[]

Deflate64 differences: length symbol 285 is base 3 + 16 extra bits; two more distance codes. InflateDecoder

NameValueTypeNotes
LengthBase64[3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 1…ushort[]
LengthExtra64[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 16]byte[]
DistanceBase64[1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1…int[]
DistanceExtra64[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, …byte[]
CodeLengthOrder[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]byte[]
FixedLiteralsBuildFixedLiterals()Huffman
FixedDistancesBuildFixedDistances(30)Huffman
FixedDistances64BuildFixedDistances(32)Huffman

Implementation limits reader

ClassNameValueNotes
GzipCarverMaxNameLength1024
GzipCarverMinOutputForPartial4096
Structures and constants were extracted from: Carving/Plugins/Compressed/GzipCarver.cs, Carving/Plugins/Compressed/InflateDecoder.cs, Modules/FileSystems/GzipArchiveModule.cs. Prose sections are a summary from public sources; verify details before relying on them.