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