1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncNetwork Working Group P. Deutsch
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRequest for Comments: 1952 Aladdin Enterprises
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncCategory: Informational May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync GZIP file format specification version 4.3
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncStatus of This Memo
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This memo provides information for the Internet community. This memo
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync does not specify an Internet standard of any kind. Distribution of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync this memo is unlimited.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncIESG Note:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The IESG takes no position on the validity of any Intellectual
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Property Rights statements contained in this document.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncNotices
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Copyright (c) 1996 L. Peter Deutsch
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Permission is granted to copy and distribute this document for any
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync purpose and without charge, including translations into other
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync languages and incorporation into compilations, provided that the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync copyright notice and this notice are preserved, and that any
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync substantive changes or deletions from the original are clearly
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync marked.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync A pointer to the latest version of this and related documentation in
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync HTML format can be found at the URL
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncAbstract
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This specification defines a lossless compressed data format that is
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compatible with the widely used GZIP utility. The format includes a
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync cyclic redundancy check value for detecting data corruption. The
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync format presently uses the DEFLATE method of compression but can be
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync easily extended to use other compression methods. The format can be
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync implemented readily in a manner not covered by patents.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 1]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncTable of Contents
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1. Introduction ................................................... 2
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.1. Purpose ................................................... 2
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.2. Intended audience ......................................... 3
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.3. Scope ..................................................... 3
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.4. Compliance ................................................ 3
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.5. Definitions of terms and conventions used ................. 3
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.6. Changes from previous versions ............................ 3
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2. Detailed specification ......................................... 4
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.1. Overall conventions ....................................... 4
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.2. File format ............................................... 5
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3. Member format ............................................. 5
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3.1. Member header and trailer ........................... 6
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3.1.1. Extra field ................................... 8
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3.1.2. Compliance .................................... 9
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 3. References .................................................. 9
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 4. Security Considerations .................................... 10
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 5. Acknowledgements ........................................... 10
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 6. Author's Address ........................................... 10
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 7. Appendix: Jean-Loup Gailly's gzip utility .................. 11
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 8. Appendix: Sample CRC Code .................................. 11
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync1. Introduction
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.1. Purpose
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The purpose of this specification is to define a lossless
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compressed data format that:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Is independent of CPU type, operating system, file system,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync and character set, and hence can be used for interchange;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Can compress or decompress a data stream (as opposed to a
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync randomly accessible file) to produce another data stream,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync using only an a priori bounded amount of intermediate
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync storage, and hence can be used in data communications or
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync similar structures such as Unix filters;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Compresses data with efficiency comparable to the best
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync currently available general-purpose compression methods,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync and in particular considerably better than the "compress"
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync program;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Can be implemented readily in a manner not covered by
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync patents, and hence can be practiced freely;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Is compatible with the file format produced by the current
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync widely used gzip utility, in that conforming decompressors
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync will be able to read data produced by the existing gzip
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compressor.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 2]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The data format defined by this specification does not attempt to:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Provide random access to compressed data;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Compress specialized data (e.g., raster graphics) as well as
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the best currently available specialized algorithms.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.2. Intended audience
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This specification is intended for use by implementors of software
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync to compress data into gzip format and/or decompress data from gzip
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync format.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The text of the specification assumes a basic background in
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync programming at the level of bits and other primitive data
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync representations.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.3. Scope
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The specification specifies a compression method and a file format
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (the latter assuming only that a file can store a sequence of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync arbitrary bytes). It does not specify any particular interface to
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync a file system or anything about character sets or encodings
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (except for file names and comments, which are optional).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.4. Compliance
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Unless otherwise indicated below, a compliant decompressor must be
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync able to accept and decompress any file that conforms to all the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync specifications presented here; a compliant compressor must produce
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync files that conform to all the specifications presented here. The
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync material in the appendices is not part of the specification per se
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync and is not relevant to compliance.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.5. Definitions of terms and conventions used
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync byte: 8 bits stored or transmitted as a unit (same as an octet).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (For this specification, a byte is exactly 8 bits, even on
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync machines which store a character on a number of bits different
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync from 8.) See below for the numbering of bits within a byte.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.6. Changes from previous versions
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync There have been no technical changes to the gzip format since
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync version 4.1 of this specification. In version 4.2, some
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync terminology was changed, and the sample CRC code was rewritten for
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync clarity and to eliminate the requirement for the caller to do pre-
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync and post-conditioning. Version 4.3 is a conversion of the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync specification to RFC style.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 3]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync2. Detailed specification
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.1. Overall conventions
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync In the diagrams below, a box like this:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | | <-- the vertical bars might be missing
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync represents one byte; a box like this:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +==============+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | |
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +==============+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync represents a variable number of bytes.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Bytes stored within a computer do not have a "bit order", since
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync they are always treated as a unit. However, a byte considered as
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync an integer between 0 and 255 does have a most- and least-
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync significant bit, and since we write numbers with the most-
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync significant digit on the left, we also write bytes with the most-
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync significant bit on the left. In the diagrams below, we number the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bits of a byte so that bit 0 is the least-significant bit, i.e.,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the bits are numbered:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +--------+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |76543210|
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +--------+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This document does not address the issue of the order in which
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bits of a byte are transmitted on a bit-sequential medium, since
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the data format described here is byte- rather than bit-oriented.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Within a computer, a number may occupy multiple bytes. All
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync multi-byte numbers in the format described here are stored with
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the least-significant byte first (at the lower memory address).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync For example, the decimal number 520 is stored as:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 0 1
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +--------+--------+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |00001000|00000010|
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +--------+--------+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ^ ^
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | |
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | + more significant byte = 2 x 256
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync + less significant byte = 8
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 4]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.2. File format
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync A gzip file consists of a series of "members" (compressed data
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync sets). The format of each member is specified in the following
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync section. The members simply appear one after another in the file,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync with no additional information before, between, or after them.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3. Member format
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Each member has the following structure:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+---+---+---+---+---+---+---+---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+---+---+---+---+---+---+---+---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (if FLG.FEXTRA set)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+=================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | XLEN |...XLEN bytes of "extra field"...| (more-->)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+=================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (if FLG.FNAME set)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +=========================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |...original file name, zero-terminated...| (more-->)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +=========================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (if FLG.FCOMMENT set)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +===================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |...file comment, zero-terminated...| (more-->)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +===================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (if FLG.FHCRC set)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | CRC16 |
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +=======================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |...compressed blocks...| (more-->)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +=======================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 0 1 2 3 4 5 6 7
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+---+---+---+---+---+---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync | CRC32 | ISIZE |
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+---+---+---+---+---+---+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 5]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3.1. Member header and trailer
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ID1 (IDentification 1)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ID2 (IDentification 2)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync (0x8b, \213), to identify the file as being in gzip format.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync CM (Compression Method)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This identifies the compression method used in the file. CM
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync = 0-7 are reserved. CM = 8 denotes the "deflate"
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compression method, which is the one customarily used by
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync gzip and which is documented elsewhere.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync FLG (FLaGs)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This flag byte is divided into individual bits as follows:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 0 FTEXT
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 1 FHCRC
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 2 FEXTRA
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 3 FNAME
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 4 FCOMMENT
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 5 reserved
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 6 reserved
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit 7 reserved
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If FTEXT is set, the file is probably ASCII text. This is
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync an optional indication, which the compressor may set by
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync checking a small amount of the input data to see whether any
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync non-ASCII characters are present. In case of doubt, FTEXT
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync is cleared, indicating binary data. For systems which have
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync different file formats for ascii text and binary data, the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync decompressor can use FTEXT to choose the appropriate format.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync We deliberately do not specify the algorithm used to set
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync this bit, since a compressor always has the option of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync leaving it cleared and a decompressor always has the option
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync of ignoring it and letting some other program handle issues
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync of data conversion.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If FHCRC is set, a CRC16 for the gzip header is present,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync immediately before the compressed data. The CRC16 consists
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync of the two least significant bytes of the CRC32 for all
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bytes of the gzip header up to and not including the CRC16.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [The FHCRC bit was never set by versions of gzip up to
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1.2.4, even though it was documented with a different
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync meaning in gzip 1.2.4.]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If FEXTRA is set, optional extra fields are present, as
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync described in a following section.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 6]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If FNAME is set, an original file name is present,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync terminated by a zero byte. The name must consist of ISO
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 8859-1 (LATIN-1) characters; on operating systems using
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync EBCDIC or any other character set for file names, the name
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync must be translated to the ISO LATIN-1 character set. This
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync is the original name of the file being compressed, with any
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync directory components removed, and, if the file being
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compressed is on a file system with case insensitive names,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync forced to lower case. There is no original file name if the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync data was compressed from a source other than a named file;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync for example, if the source was stdin on a Unix system, there
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync is no file name.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If FCOMMENT is set, a zero-terminated file comment is
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync present. This comment is not interpreted; it is only
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync intended for human consumption. The comment must consist of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ISO 8859-1 (LATIN-1) characters. Line breaks should be
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync denoted by a single line feed character (10 decimal).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Reserved FLG bits must be zero.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync MTIME (Modification TIME)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This gives the most recent modification time of the original
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync file being compressed. The time is in Unix format, i.e.,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync may cause problems for MS-DOS and other systems that use
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync local rather than Universal time.) If the compressed data
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync did not come from a file, MTIME is set to the time at which
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compression started. MTIME = 0 means no time stamp is
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync available.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync XFL (eXtra FLags)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync These flags are available for use by specific compression
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync methods. The "deflate" method (CM = 8) sets these flags as
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync follows:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync XFL = 2 - compressor used maximum compression,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync slowest algorithm
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync XFL = 4 - compressor used fastest algorithm
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync OS (Operating System)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This identifies the type of file system on which compression
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync took place. This may be useful in determining end-of-line
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync convention for text files. The currently defined values are
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync as follows:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 7]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 1 - Amiga
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2 - VMS (or OpenVMS)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 3 - Unix
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 4 - VM/CMS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 5 - Atari TOS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 6 - HPFS filesystem (OS/2, NT)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 7 - Macintosh
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 8 - Z-System
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 9 - CP/M
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 10 - TOPS-20
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 11 - NTFS filesystem (NT)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 12 - QDOS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 13 - Acorn RISCOS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 255 - unknown
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync XLEN (eXtra LENgth)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If FLG.FEXTRA is set, this gives the length of the optional
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync extra field. See below for details.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync CRC32 (CRC-32)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This contains a Cyclic Redundancy Check value of the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync uncompressed data computed according to CRC-32 algorithm
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync used in the ISO 3309 standard and in section 8.1.1.6.2 of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ITU-T recommendation V.42. (See http://www.iso.ch for
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ordering ISO documents. See gopher://info.itu.ch for an
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync online version of ITU-T V.42.)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ISIZE (Input SIZE)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync This contains the size of the original (uncompressed) input
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync data modulo 2^32.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3.1.1. Extra field
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync If the FLG.FEXTRA bit is set, an "extra field" is present in
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the header, with total length XLEN bytes. It consists of a
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync series of subfields, each of the form:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+---+---+==================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync |SI1|SI2| LEN |... LEN bytes of subfield data ...|
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync +---+---+---+---+==================================+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync SI1 and SI2 provide a subfield ID, typically two ASCII letters
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync with some mnemonic value. Jean-Loup Gailly
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync <gzip@prep.ai.mit.edu> is maintaining a registry of subfield
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync IDs; please send him any subfield ID you wish to use. Subfield
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync IDs with SI2 = 0 are reserved for future use. The following
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync IDs are currently defined:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 8]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync SI1 SI2 Data
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ---------- ---------- ----
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 0x41 ('A') 0x70 ('P') Apollo file type information
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync LEN gives the length of the subfield data, excluding the 4
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync initial bytes.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 2.3.1.2. Compliance
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync A compliant compressor must produce files with correct ID1,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ID2, CM, CRC32, and ISIZE, but may set all the other fields in
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the fixed-length part of the header to default values (255 for
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync OS, 0 for all others). The compressor must set all reserved
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bits to zero.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync A compliant decompressor must check ID1, ID2, and CM, and
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync provide an error indication if any of these have incorrect
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync at least so it can skip over the optional fields if they are
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync present. It need not examine any other part of the header or
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync trailer; in particular, a decompressor may ignore FTEXT and OS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync and always produce binary output, and still be compliant. A
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync compliant decompressor must give an error indication if any
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync reserved bit is non-zero, since such a bit could indicate the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync presence of a new field that would cause subsequent data to be
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync interpreted incorrectly.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync3. References
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [1] "Information Processing - 8-bit single-byte coded graphic
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The ISO 8859-1 (Latin-1) character set is a superset of 7-bit
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ASCII. Files defining this character set are available as
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [2] ISO 3309
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [3] ITU-T recommendation V.42
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification",
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync available in ftp://ftp.uu.net/pub/archiving/zip/doc/
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ftp://prep.ai.mit.edu/pub/gnu/
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Look-Up", Communications of the ACM, 31(8), pp.1008-1013.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 9]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync pp.118-133.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync describing the CRC concept.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync4. Security Considerations
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Any data compression method involves the reduction of redundancy in
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the data. Consequently, any corruption of the data is likely to have
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync severe effects and be difficult to correct. Uncompressed text, on
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the other hand, will probably still be readable despite the presence
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync of some corrupted bytes.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync It is recommended that systems using this data format provide some
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync means of validating the integrity of the compressed data, such as by
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync setting and checking the CRC-32 check value.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync5. Acknowledgements
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Trademarks cited in this document are the property of their
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync respective owners.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the related software described in this specification. Glenn
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Randers-Pehrson converted this document to RFC and HTML format.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync6. Author's Address
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync L. Peter Deutsch
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Aladdin Enterprises
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 203 Santa Margarita Ave.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Menlo Park, CA 94025
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Phone: (415) 322-0103 (AM only)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync FAX: (415) 322-1734
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync EMail: <ghost@aladdin.com>
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Questions about the technical content of this specification can be
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync sent by email to:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Jean-Loup Gailly <gzip@prep.ai.mit.edu> and
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Mark Adler <madler@alumni.caltech.edu>
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Editorial comments on this specification can be sent by email to:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync L. Peter Deutsch <ghost@aladdin.com> and
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 10]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync7. Appendix: Jean-Loup Gailly's gzip utility
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The most widely used implementation of gzip compression, and the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync original documentation on which this specification is based, were
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync created by Jean-Loup Gailly <gzip@prep.ai.mit.edu>. Since this
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync implementation is a de facto standard, we mention some more of its
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync features here. Again, the material in this section is not part of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the specification per se, and implementations need not follow it to
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync be compliant.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync When compressing or decompressing a file, gzip preserves the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync protection, ownership, and modification time attributes on the local
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync file system, since there is no provision for representing protection
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync attributes in the gzip file format itself. Since the file format
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync includes a modification time, the gzip decompressor provides a
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync command line switch that assigns the modification time from the file,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync rather than the local modification time of the compressed input, to
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the decompressed output.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync8. Appendix: Sample CRC Code
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The following sample code represents a practical implementation of
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync for a formal specification.)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync The sample code is in the ANSI C programming language. Non C users
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync may find it easier to read with these hints:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync & Bitwise AND operator.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ^ Bitwise exclusive-OR operator.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync >> Bitwise right shift operator. When applied to an
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned quantity, as here, right shift inserts zero
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync bit(s) at the left.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ! Logical NOT operator.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ++ "n++" increments the variable n.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync 0xNNN 0x introduces a hexadecimal (base 16) constant.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Suffix L indicates a long value (at least 32 bits).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /* Table of CRCs of all 8-bit messages. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned long crc_table[256];
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /* Flag: has the table been computed? Initially false. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync int crc_table_computed = 0;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /* Make the table for a fast CRC. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync void make_crc_table(void)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned long c;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 11]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncRFC 1952 GZIP File Format Specification May 1996
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync int n, k;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync for (n = 0; n < 256; n++) {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync c = (unsigned long) n;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync for (k = 0; k < 8; k++) {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync if (c & 1) {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync c = 0xedb88320L ^ (c >> 1);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync } else {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync c = c >> 1;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync crc_table[n] = c;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync crc_table_computed = 1;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /*
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync Update a running crc with the bytes buf[0..len-1] and return
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync the updated crc. The crc should be initialized to zero. Pre- and
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync post-conditioning (one's complement) is performed within this
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync function so it shouldn't be done by the caller. Usage example:
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned long crc = 0L;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync while (read_buffer(buffer, length) != EOF) {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync crc = update_crc(crc, buffer, length);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync if (crc != original_crc) error();
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned long update_crc(unsigned long crc,
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned char *buf, int len)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned long c = crc ^ 0xffffffffL;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync int n;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync if (!crc_table_computed)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync make_crc_table();
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync for (n = 0; n < len; n++) {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync return c ^ 0xffffffffL;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /* Return the CRC of the bytes buf[0..len-1]. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync unsigned long crc(unsigned char *buf, int len)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync {
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync return update_crc(0L, buf, len);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync }
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncDeutsch Informational [Page 12]
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync