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
| Offset | Size | Type | Field | Notes |
|---|---|---|---|---|
| 0x0 | 4 | u32 LE | – | |
| 0x4 | 4 | u32 LE | – |
MemberHeader.ReadHeader buffer header · GzipCarver.cs
| Offset | Size | Type | Field | Notes |
|---|---|---|---|---|
| 0x0 | 1 | u8 | – | |
| 0x1 | 1 | u8 | – | |
| 0x2 | 1 | u8 | – | |
| 0x3 | 1 | u8 | – | |
| 0x3 | 1 | u8 | Flags | |
| 0x4 | 4 | u32 LE | Time | |
| 0x8 | 1 | u8 | Null | |
| 0x9 | 1 | u8 | Null |
Constants
General InflateDecoder
| Name | Value | Type | Notes |
|---|---|---|---|
| OutputChunk | 65536 | int | |
| FastBits | 10 | int | |
| 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
| Name | Value | Type | Notes |
|---|---|---|---|
| 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[] | |
| FixedLiterals | BuildFixedLiterals() | Huffman | |
| FixedDistances | BuildFixedDistances(30) | Huffman | |
| FixedDistances64 | BuildFixedDistances(32) | Huffman |
Implementation limits reader
| Class | Name | Value | Notes |
|---|---|---|---|
| GzipCarver | MaxNameLength | 1024 | |
| GzipCarver | MinOutputForPartial | 4096 |