annotate src/zlib-1.2.8/doc/rfc1952.txt @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 5b4145a0d408
children
rev   line source
cannam@128 1
cannam@128 2
cannam@128 3
cannam@128 4
cannam@128 5
cannam@128 6
cannam@128 7 Network Working Group P. Deutsch
cannam@128 8 Request for Comments: 1952 Aladdin Enterprises
cannam@128 9 Category: Informational May 1996
cannam@128 10
cannam@128 11
cannam@128 12 GZIP file format specification version 4.3
cannam@128 13
cannam@128 14 Status of This Memo
cannam@128 15
cannam@128 16 This memo provides information for the Internet community. This memo
cannam@128 17 does not specify an Internet standard of any kind. Distribution of
cannam@128 18 this memo is unlimited.
cannam@128 19
cannam@128 20 IESG Note:
cannam@128 21
cannam@128 22 The IESG takes no position on the validity of any Intellectual
cannam@128 23 Property Rights statements contained in this document.
cannam@128 24
cannam@128 25 Notices
cannam@128 26
cannam@128 27 Copyright (c) 1996 L. Peter Deutsch
cannam@128 28
cannam@128 29 Permission is granted to copy and distribute this document for any
cannam@128 30 purpose and without charge, including translations into other
cannam@128 31 languages and incorporation into compilations, provided that the
cannam@128 32 copyright notice and this notice are preserved, and that any
cannam@128 33 substantive changes or deletions from the original are clearly
cannam@128 34 marked.
cannam@128 35
cannam@128 36 A pointer to the latest version of this and related documentation in
cannam@128 37 HTML format can be found at the URL
cannam@128 38 <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>.
cannam@128 39
cannam@128 40 Abstract
cannam@128 41
cannam@128 42 This specification defines a lossless compressed data format that is
cannam@128 43 compatible with the widely used GZIP utility. The format includes a
cannam@128 44 cyclic redundancy check value for detecting data corruption. The
cannam@128 45 format presently uses the DEFLATE method of compression but can be
cannam@128 46 easily extended to use other compression methods. The format can be
cannam@128 47 implemented readily in a manner not covered by patents.
cannam@128 48
cannam@128 49
cannam@128 50
cannam@128 51
cannam@128 52
cannam@128 53
cannam@128 54
cannam@128 55
cannam@128 56
cannam@128 57
cannam@128 58 Deutsch Informational [Page 1]
cannam@128 59
cannam@128 60 RFC 1952 GZIP File Format Specification May 1996
cannam@128 61
cannam@128 62
cannam@128 63 Table of Contents
cannam@128 64
cannam@128 65 1. Introduction ................................................... 2
cannam@128 66 1.1. Purpose ................................................... 2
cannam@128 67 1.2. Intended audience ......................................... 3
cannam@128 68 1.3. Scope ..................................................... 3
cannam@128 69 1.4. Compliance ................................................ 3
cannam@128 70 1.5. Definitions of terms and conventions used ................. 3
cannam@128 71 1.6. Changes from previous versions ............................ 3
cannam@128 72 2. Detailed specification ......................................... 4
cannam@128 73 2.1. Overall conventions ....................................... 4
cannam@128 74 2.2. File format ............................................... 5
cannam@128 75 2.3. Member format ............................................. 5
cannam@128 76 2.3.1. Member header and trailer ........................... 6
cannam@128 77 2.3.1.1. Extra field ................................... 8
cannam@128 78 2.3.1.2. Compliance .................................... 9
cannam@128 79 3. References .................................................. 9
cannam@128 80 4. Security Considerations .................................... 10
cannam@128 81 5. Acknowledgements ........................................... 10
cannam@128 82 6. Author's Address ........................................... 10
cannam@128 83 7. Appendix: Jean-Loup Gailly's gzip utility .................. 11
cannam@128 84 8. Appendix: Sample CRC Code .................................. 11
cannam@128 85
cannam@128 86 1. Introduction
cannam@128 87
cannam@128 88 1.1. Purpose
cannam@128 89
cannam@128 90 The purpose of this specification is to define a lossless
cannam@128 91 compressed data format that:
cannam@128 92
cannam@128 93 * Is independent of CPU type, operating system, file system,
cannam@128 94 and character set, and hence can be used for interchange;
cannam@128 95 * Can compress or decompress a data stream (as opposed to a
cannam@128 96 randomly accessible file) to produce another data stream,
cannam@128 97 using only an a priori bounded amount of intermediate
cannam@128 98 storage, and hence can be used in data communications or
cannam@128 99 similar structures such as Unix filters;
cannam@128 100 * Compresses data with efficiency comparable to the best
cannam@128 101 currently available general-purpose compression methods,
cannam@128 102 and in particular considerably better than the "compress"
cannam@128 103 program;
cannam@128 104 * Can be implemented readily in a manner not covered by
cannam@128 105 patents, and hence can be practiced freely;
cannam@128 106 * Is compatible with the file format produced by the current
cannam@128 107 widely used gzip utility, in that conforming decompressors
cannam@128 108 will be able to read data produced by the existing gzip
cannam@128 109 compressor.
cannam@128 110
cannam@128 111
cannam@128 112
cannam@128 113
cannam@128 114 Deutsch Informational [Page 2]
cannam@128 115
cannam@128 116 RFC 1952 GZIP File Format Specification May 1996
cannam@128 117
cannam@128 118
cannam@128 119 The data format defined by this specification does not attempt to:
cannam@128 120
cannam@128 121 * Provide random access to compressed data;
cannam@128 122 * Compress specialized data (e.g., raster graphics) as well as
cannam@128 123 the best currently available specialized algorithms.
cannam@128 124
cannam@128 125 1.2. Intended audience
cannam@128 126
cannam@128 127 This specification is intended for use by implementors of software
cannam@128 128 to compress data into gzip format and/or decompress data from gzip
cannam@128 129 format.
cannam@128 130
cannam@128 131 The text of the specification assumes a basic background in
cannam@128 132 programming at the level of bits and other primitive data
cannam@128 133 representations.
cannam@128 134
cannam@128 135 1.3. Scope
cannam@128 136
cannam@128 137 The specification specifies a compression method and a file format
cannam@128 138 (the latter assuming only that a file can store a sequence of
cannam@128 139 arbitrary bytes). It does not specify any particular interface to
cannam@128 140 a file system or anything about character sets or encodings
cannam@128 141 (except for file names and comments, which are optional).
cannam@128 142
cannam@128 143 1.4. Compliance
cannam@128 144
cannam@128 145 Unless otherwise indicated below, a compliant decompressor must be
cannam@128 146 able to accept and decompress any file that conforms to all the
cannam@128 147 specifications presented here; a compliant compressor must produce
cannam@128 148 files that conform to all the specifications presented here. The
cannam@128 149 material in the appendices is not part of the specification per se
cannam@128 150 and is not relevant to compliance.
cannam@128 151
cannam@128 152 1.5. Definitions of terms and conventions used
cannam@128 153
cannam@128 154 byte: 8 bits stored or transmitted as a unit (same as an octet).
cannam@128 155 (For this specification, a byte is exactly 8 bits, even on
cannam@128 156 machines which store a character on a number of bits different
cannam@128 157 from 8.) See below for the numbering of bits within a byte.
cannam@128 158
cannam@128 159 1.6. Changes from previous versions
cannam@128 160
cannam@128 161 There have been no technical changes to the gzip format since
cannam@128 162 version 4.1 of this specification. In version 4.2, some
cannam@128 163 terminology was changed, and the sample CRC code was rewritten for
cannam@128 164 clarity and to eliminate the requirement for the caller to do pre-
cannam@128 165 and post-conditioning. Version 4.3 is a conversion of the
cannam@128 166 specification to RFC style.
cannam@128 167
cannam@128 168
cannam@128 169
cannam@128 170 Deutsch Informational [Page 3]
cannam@128 171
cannam@128 172 RFC 1952 GZIP File Format Specification May 1996
cannam@128 173
cannam@128 174
cannam@128 175 2. Detailed specification
cannam@128 176
cannam@128 177 2.1. Overall conventions
cannam@128 178
cannam@128 179 In the diagrams below, a box like this:
cannam@128 180
cannam@128 181 +---+
cannam@128 182 | | <-- the vertical bars might be missing
cannam@128 183 +---+
cannam@128 184
cannam@128 185 represents one byte; a box like this:
cannam@128 186
cannam@128 187 +==============+
cannam@128 188 | |
cannam@128 189 +==============+
cannam@128 190
cannam@128 191 represents a variable number of bytes.
cannam@128 192
cannam@128 193 Bytes stored within a computer do not have a "bit order", since
cannam@128 194 they are always treated as a unit. However, a byte considered as
cannam@128 195 an integer between 0 and 255 does have a most- and least-
cannam@128 196 significant bit, and since we write numbers with the most-
cannam@128 197 significant digit on the left, we also write bytes with the most-
cannam@128 198 significant bit on the left. In the diagrams below, we number the
cannam@128 199 bits of a byte so that bit 0 is the least-significant bit, i.e.,
cannam@128 200 the bits are numbered:
cannam@128 201
cannam@128 202 +--------+
cannam@128 203 |76543210|
cannam@128 204 +--------+
cannam@128 205
cannam@128 206 This document does not address the issue of the order in which
cannam@128 207 bits of a byte are transmitted on a bit-sequential medium, since
cannam@128 208 the data format described here is byte- rather than bit-oriented.
cannam@128 209
cannam@128 210 Within a computer, a number may occupy multiple bytes. All
cannam@128 211 multi-byte numbers in the format described here are stored with
cannam@128 212 the least-significant byte first (at the lower memory address).
cannam@128 213 For example, the decimal number 520 is stored as:
cannam@128 214
cannam@128 215 0 1
cannam@128 216 +--------+--------+
cannam@128 217 |00001000|00000010|
cannam@128 218 +--------+--------+
cannam@128 219 ^ ^
cannam@128 220 | |
cannam@128 221 | + more significant byte = 2 x 256
cannam@128 222 + less significant byte = 8
cannam@128 223
cannam@128 224
cannam@128 225
cannam@128 226 Deutsch Informational [Page 4]
cannam@128 227
cannam@128 228 RFC 1952 GZIP File Format Specification May 1996
cannam@128 229
cannam@128 230
cannam@128 231 2.2. File format
cannam@128 232
cannam@128 233 A gzip file consists of a series of "members" (compressed data
cannam@128 234 sets). The format of each member is specified in the following
cannam@128 235 section. The members simply appear one after another in the file,
cannam@128 236 with no additional information before, between, or after them.
cannam@128 237
cannam@128 238 2.3. Member format
cannam@128 239
cannam@128 240 Each member has the following structure:
cannam@128 241
cannam@128 242 +---+---+---+---+---+---+---+---+---+---+
cannam@128 243 |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
cannam@128 244 +---+---+---+---+---+---+---+---+---+---+
cannam@128 245
cannam@128 246 (if FLG.FEXTRA set)
cannam@128 247
cannam@128 248 +---+---+=================================+
cannam@128 249 | XLEN |...XLEN bytes of "extra field"...| (more-->)
cannam@128 250 +---+---+=================================+
cannam@128 251
cannam@128 252 (if FLG.FNAME set)
cannam@128 253
cannam@128 254 +=========================================+
cannam@128 255 |...original file name, zero-terminated...| (more-->)
cannam@128 256 +=========================================+
cannam@128 257
cannam@128 258 (if FLG.FCOMMENT set)
cannam@128 259
cannam@128 260 +===================================+
cannam@128 261 |...file comment, zero-terminated...| (more-->)
cannam@128 262 +===================================+
cannam@128 263
cannam@128 264 (if FLG.FHCRC set)
cannam@128 265
cannam@128 266 +---+---+
cannam@128 267 | CRC16 |
cannam@128 268 +---+---+
cannam@128 269
cannam@128 270 +=======================+
cannam@128 271 |...compressed blocks...| (more-->)
cannam@128 272 +=======================+
cannam@128 273
cannam@128 274 0 1 2 3 4 5 6 7
cannam@128 275 +---+---+---+---+---+---+---+---+
cannam@128 276 | CRC32 | ISIZE |
cannam@128 277 +---+---+---+---+---+---+---+---+
cannam@128 278
cannam@128 279
cannam@128 280
cannam@128 281
cannam@128 282 Deutsch Informational [Page 5]
cannam@128 283
cannam@128 284 RFC 1952 GZIP File Format Specification May 1996
cannam@128 285
cannam@128 286
cannam@128 287 2.3.1. Member header and trailer
cannam@128 288
cannam@128 289 ID1 (IDentification 1)
cannam@128 290 ID2 (IDentification 2)
cannam@128 291 These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139
cannam@128 292 (0x8b, \213), to identify the file as being in gzip format.
cannam@128 293
cannam@128 294 CM (Compression Method)
cannam@128 295 This identifies the compression method used in the file. CM
cannam@128 296 = 0-7 are reserved. CM = 8 denotes the "deflate"
cannam@128 297 compression method, which is the one customarily used by
cannam@128 298 gzip and which is documented elsewhere.
cannam@128 299
cannam@128 300 FLG (FLaGs)
cannam@128 301 This flag byte is divided into individual bits as follows:
cannam@128 302
cannam@128 303 bit 0 FTEXT
cannam@128 304 bit 1 FHCRC
cannam@128 305 bit 2 FEXTRA
cannam@128 306 bit 3 FNAME
cannam@128 307 bit 4 FCOMMENT
cannam@128 308 bit 5 reserved
cannam@128 309 bit 6 reserved
cannam@128 310 bit 7 reserved
cannam@128 311
cannam@128 312 If FTEXT is set, the file is probably ASCII text. This is
cannam@128 313 an optional indication, which the compressor may set by
cannam@128 314 checking a small amount of the input data to see whether any
cannam@128 315 non-ASCII characters are present. In case of doubt, FTEXT
cannam@128 316 is cleared, indicating binary data. For systems which have
cannam@128 317 different file formats for ascii text and binary data, the
cannam@128 318 decompressor can use FTEXT to choose the appropriate format.
cannam@128 319 We deliberately do not specify the algorithm used to set
cannam@128 320 this bit, since a compressor always has the option of
cannam@128 321 leaving it cleared and a decompressor always has the option
cannam@128 322 of ignoring it and letting some other program handle issues
cannam@128 323 of data conversion.
cannam@128 324
cannam@128 325 If FHCRC is set, a CRC16 for the gzip header is present,
cannam@128 326 immediately before the compressed data. The CRC16 consists
cannam@128 327 of the two least significant bytes of the CRC32 for all
cannam@128 328 bytes of the gzip header up to and not including the CRC16.
cannam@128 329 [The FHCRC bit was never set by versions of gzip up to
cannam@128 330 1.2.4, even though it was documented with a different
cannam@128 331 meaning in gzip 1.2.4.]
cannam@128 332
cannam@128 333 If FEXTRA is set, optional extra fields are present, as
cannam@128 334 described in a following section.
cannam@128 335
cannam@128 336
cannam@128 337
cannam@128 338 Deutsch Informational [Page 6]
cannam@128 339
cannam@128 340 RFC 1952 GZIP File Format Specification May 1996
cannam@128 341
cannam@128 342
cannam@128 343 If FNAME is set, an original file name is present,
cannam@128 344 terminated by a zero byte. The name must consist of ISO
cannam@128 345 8859-1 (LATIN-1) characters; on operating systems using
cannam@128 346 EBCDIC or any other character set for file names, the name
cannam@128 347 must be translated to the ISO LATIN-1 character set. This
cannam@128 348 is the original name of the file being compressed, with any
cannam@128 349 directory components removed, and, if the file being
cannam@128 350 compressed is on a file system with case insensitive names,
cannam@128 351 forced to lower case. There is no original file name if the
cannam@128 352 data was compressed from a source other than a named file;
cannam@128 353 for example, if the source was stdin on a Unix system, there
cannam@128 354 is no file name.
cannam@128 355
cannam@128 356 If FCOMMENT is set, a zero-terminated file comment is
cannam@128 357 present. This comment is not interpreted; it is only
cannam@128 358 intended for human consumption. The comment must consist of
cannam@128 359 ISO 8859-1 (LATIN-1) characters. Line breaks should be
cannam@128 360 denoted by a single line feed character (10 decimal).
cannam@128 361
cannam@128 362 Reserved FLG bits must be zero.
cannam@128 363
cannam@128 364 MTIME (Modification TIME)
cannam@128 365 This gives the most recent modification time of the original
cannam@128 366 file being compressed. The time is in Unix format, i.e.,
cannam@128 367 seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this
cannam@128 368 may cause problems for MS-DOS and other systems that use
cannam@128 369 local rather than Universal time.) If the compressed data
cannam@128 370 did not come from a file, MTIME is set to the time at which
cannam@128 371 compression started. MTIME = 0 means no time stamp is
cannam@128 372 available.
cannam@128 373
cannam@128 374 XFL (eXtra FLags)
cannam@128 375 These flags are available for use by specific compression
cannam@128 376 methods. The "deflate" method (CM = 8) sets these flags as
cannam@128 377 follows:
cannam@128 378
cannam@128 379 XFL = 2 - compressor used maximum compression,
cannam@128 380 slowest algorithm
cannam@128 381 XFL = 4 - compressor used fastest algorithm
cannam@128 382
cannam@128 383 OS (Operating System)
cannam@128 384 This identifies the type of file system on which compression
cannam@128 385 took place. This may be useful in determining end-of-line
cannam@128 386 convention for text files. The currently defined values are
cannam@128 387 as follows:
cannam@128 388
cannam@128 389
cannam@128 390
cannam@128 391
cannam@128 392
cannam@128 393
cannam@128 394 Deutsch Informational [Page 7]
cannam@128 395
cannam@128 396 RFC 1952 GZIP File Format Specification May 1996
cannam@128 397
cannam@128 398
cannam@128 399 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)
cannam@128 400 1 - Amiga
cannam@128 401 2 - VMS (or OpenVMS)
cannam@128 402 3 - Unix
cannam@128 403 4 - VM/CMS
cannam@128 404 5 - Atari TOS
cannam@128 405 6 - HPFS filesystem (OS/2, NT)
cannam@128 406 7 - Macintosh
cannam@128 407 8 - Z-System
cannam@128 408 9 - CP/M
cannam@128 409 10 - TOPS-20
cannam@128 410 11 - NTFS filesystem (NT)
cannam@128 411 12 - QDOS
cannam@128 412 13 - Acorn RISCOS
cannam@128 413 255 - unknown
cannam@128 414
cannam@128 415 XLEN (eXtra LENgth)
cannam@128 416 If FLG.FEXTRA is set, this gives the length of the optional
cannam@128 417 extra field. See below for details.
cannam@128 418
cannam@128 419 CRC32 (CRC-32)
cannam@128 420 This contains a Cyclic Redundancy Check value of the
cannam@128 421 uncompressed data computed according to CRC-32 algorithm
cannam@128 422 used in the ISO 3309 standard and in section 8.1.1.6.2 of
cannam@128 423 ITU-T recommendation V.42. (See http://www.iso.ch for
cannam@128 424 ordering ISO documents. See gopher://info.itu.ch for an
cannam@128 425 online version of ITU-T V.42.)
cannam@128 426
cannam@128 427 ISIZE (Input SIZE)
cannam@128 428 This contains the size of the original (uncompressed) input
cannam@128 429 data modulo 2^32.
cannam@128 430
cannam@128 431 2.3.1.1. Extra field
cannam@128 432
cannam@128 433 If the FLG.FEXTRA bit is set, an "extra field" is present in
cannam@128 434 the header, with total length XLEN bytes. It consists of a
cannam@128 435 series of subfields, each of the form:
cannam@128 436
cannam@128 437 +---+---+---+---+==================================+
cannam@128 438 |SI1|SI2| LEN |... LEN bytes of subfield data ...|
cannam@128 439 +---+---+---+---+==================================+
cannam@128 440
cannam@128 441 SI1 and SI2 provide a subfield ID, typically two ASCII letters
cannam@128 442 with some mnemonic value. Jean-Loup Gailly
cannam@128 443 <gzip@prep.ai.mit.edu> is maintaining a registry of subfield
cannam@128 444 IDs; please send him any subfield ID you wish to use. Subfield
cannam@128 445 IDs with SI2 = 0 are reserved for future use. The following
cannam@128 446 IDs are currently defined:
cannam@128 447
cannam@128 448
cannam@128 449
cannam@128 450 Deutsch Informational [Page 8]
cannam@128 451
cannam@128 452 RFC 1952 GZIP File Format Specification May 1996
cannam@128 453
cannam@128 454
cannam@128 455 SI1 SI2 Data
cannam@128 456 ---------- ---------- ----
cannam@128 457 0x41 ('A') 0x70 ('P') Apollo file type information
cannam@128 458
cannam@128 459 LEN gives the length of the subfield data, excluding the 4
cannam@128 460 initial bytes.
cannam@128 461
cannam@128 462 2.3.1.2. Compliance
cannam@128 463
cannam@128 464 A compliant compressor must produce files with correct ID1,
cannam@128 465 ID2, CM, CRC32, and ISIZE, but may set all the other fields in
cannam@128 466 the fixed-length part of the header to default values (255 for
cannam@128 467 OS, 0 for all others). The compressor must set all reserved
cannam@128 468 bits to zero.
cannam@128 469
cannam@128 470 A compliant decompressor must check ID1, ID2, and CM, and
cannam@128 471 provide an error indication if any of these have incorrect
cannam@128 472 values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC
cannam@128 473 at least so it can skip over the optional fields if they are
cannam@128 474 present. It need not examine any other part of the header or
cannam@128 475 trailer; in particular, a decompressor may ignore FTEXT and OS
cannam@128 476 and always produce binary output, and still be compliant. A
cannam@128 477 compliant decompressor must give an error indication if any
cannam@128 478 reserved bit is non-zero, since such a bit could indicate the
cannam@128 479 presence of a new field that would cause subsequent data to be
cannam@128 480 interpreted incorrectly.
cannam@128 481
cannam@128 482 3. References
cannam@128 483
cannam@128 484 [1] "Information Processing - 8-bit single-byte coded graphic
cannam@128 485 character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987).
cannam@128 486 The ISO 8859-1 (Latin-1) character set is a superset of 7-bit
cannam@128 487 ASCII. Files defining this character set are available as
cannam@128 488 iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/
cannam@128 489
cannam@128 490 [2] ISO 3309
cannam@128 491
cannam@128 492 [3] ITU-T recommendation V.42
cannam@128 493
cannam@128 494 [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification",
cannam@128 495 available in ftp://ftp.uu.net/pub/archiving/zip/doc/
cannam@128 496
cannam@128 497 [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in
cannam@128 498 ftp://prep.ai.mit.edu/pub/gnu/
cannam@128 499
cannam@128 500 [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table
cannam@128 501 Look-Up", Communications of the ACM, 31(8), pp.1008-1013.
cannam@128 502
cannam@128 503
cannam@128 504
cannam@128 505
cannam@128 506 Deutsch Informational [Page 9]
cannam@128 507
cannam@128 508 RFC 1952 GZIP File Format Specification May 1996
cannam@128 509
cannam@128 510
cannam@128 511 [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal,
cannam@128 512 pp.118-133.
cannam@128 513
cannam@128 514 [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt,
cannam@128 515 describing the CRC concept.
cannam@128 516
cannam@128 517 4. Security Considerations
cannam@128 518
cannam@128 519 Any data compression method involves the reduction of redundancy in
cannam@128 520 the data. Consequently, any corruption of the data is likely to have
cannam@128 521 severe effects and be difficult to correct. Uncompressed text, on
cannam@128 522 the other hand, will probably still be readable despite the presence
cannam@128 523 of some corrupted bytes.
cannam@128 524
cannam@128 525 It is recommended that systems using this data format provide some
cannam@128 526 means of validating the integrity of the compressed data, such as by
cannam@128 527 setting and checking the CRC-32 check value.
cannam@128 528
cannam@128 529 5. Acknowledgements
cannam@128 530
cannam@128 531 Trademarks cited in this document are the property of their
cannam@128 532 respective owners.
cannam@128 533
cannam@128 534 Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler,
cannam@128 535 the related software described in this specification. Glenn
cannam@128 536 Randers-Pehrson converted this document to RFC and HTML format.
cannam@128 537
cannam@128 538 6. Author's Address
cannam@128 539
cannam@128 540 L. Peter Deutsch
cannam@128 541 Aladdin Enterprises
cannam@128 542 203 Santa Margarita Ave.
cannam@128 543 Menlo Park, CA 94025
cannam@128 544
cannam@128 545 Phone: (415) 322-0103 (AM only)
cannam@128 546 FAX: (415) 322-1734
cannam@128 547 EMail: <ghost@aladdin.com>
cannam@128 548
cannam@128 549 Questions about the technical content of this specification can be
cannam@128 550 sent by email to:
cannam@128 551
cannam@128 552 Jean-Loup Gailly <gzip@prep.ai.mit.edu> and
cannam@128 553 Mark Adler <madler@alumni.caltech.edu>
cannam@128 554
cannam@128 555 Editorial comments on this specification can be sent by email to:
cannam@128 556
cannam@128 557 L. Peter Deutsch <ghost@aladdin.com> and
cannam@128 558 Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
cannam@128 559
cannam@128 560
cannam@128 561
cannam@128 562 Deutsch Informational [Page 10]
cannam@128 563
cannam@128 564 RFC 1952 GZIP File Format Specification May 1996
cannam@128 565
cannam@128 566
cannam@128 567 7. Appendix: Jean-Loup Gailly's gzip utility
cannam@128 568
cannam@128 569 The most widely used implementation of gzip compression, and the
cannam@128 570 original documentation on which this specification is based, were
cannam@128 571 created by Jean-Loup Gailly <gzip@prep.ai.mit.edu>. Since this
cannam@128 572 implementation is a de facto standard, we mention some more of its
cannam@128 573 features here. Again, the material in this section is not part of
cannam@128 574 the specification per se, and implementations need not follow it to
cannam@128 575 be compliant.
cannam@128 576
cannam@128 577 When compressing or decompressing a file, gzip preserves the
cannam@128 578 protection, ownership, and modification time attributes on the local
cannam@128 579 file system, since there is no provision for representing protection
cannam@128 580 attributes in the gzip file format itself. Since the file format
cannam@128 581 includes a modification time, the gzip decompressor provides a
cannam@128 582 command line switch that assigns the modification time from the file,
cannam@128 583 rather than the local modification time of the compressed input, to
cannam@128 584 the decompressed output.
cannam@128 585
cannam@128 586 8. Appendix: Sample CRC Code
cannam@128 587
cannam@128 588 The following sample code represents a practical implementation of
cannam@128 589 the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42
cannam@128 590 for a formal specification.)
cannam@128 591
cannam@128 592 The sample code is in the ANSI C programming language. Non C users
cannam@128 593 may find it easier to read with these hints:
cannam@128 594
cannam@128 595 & Bitwise AND operator.
cannam@128 596 ^ Bitwise exclusive-OR operator.
cannam@128 597 >> Bitwise right shift operator. When applied to an
cannam@128 598 unsigned quantity, as here, right shift inserts zero
cannam@128 599 bit(s) at the left.
cannam@128 600 ! Logical NOT operator.
cannam@128 601 ++ "n++" increments the variable n.
cannam@128 602 0xNNN 0x introduces a hexadecimal (base 16) constant.
cannam@128 603 Suffix L indicates a long value (at least 32 bits).
cannam@128 604
cannam@128 605 /* Table of CRCs of all 8-bit messages. */
cannam@128 606 unsigned long crc_table[256];
cannam@128 607
cannam@128 608 /* Flag: has the table been computed? Initially false. */
cannam@128 609 int crc_table_computed = 0;
cannam@128 610
cannam@128 611 /* Make the table for a fast CRC. */
cannam@128 612 void make_crc_table(void)
cannam@128 613 {
cannam@128 614 unsigned long c;
cannam@128 615
cannam@128 616
cannam@128 617
cannam@128 618 Deutsch Informational [Page 11]
cannam@128 619
cannam@128 620 RFC 1952 GZIP File Format Specification May 1996
cannam@128 621
cannam@128 622
cannam@128 623 int n, k;
cannam@128 624 for (n = 0; n < 256; n++) {
cannam@128 625 c = (unsigned long) n;
cannam@128 626 for (k = 0; k < 8; k++) {
cannam@128 627 if (c & 1) {
cannam@128 628 c = 0xedb88320L ^ (c >> 1);
cannam@128 629 } else {
cannam@128 630 c = c >> 1;
cannam@128 631 }
cannam@128 632 }
cannam@128 633 crc_table[n] = c;
cannam@128 634 }
cannam@128 635 crc_table_computed = 1;
cannam@128 636 }
cannam@128 637
cannam@128 638 /*
cannam@128 639 Update a running crc with the bytes buf[0..len-1] and return
cannam@128 640 the updated crc. The crc should be initialized to zero. Pre- and
cannam@128 641 post-conditioning (one's complement) is performed within this
cannam@128 642 function so it shouldn't be done by the caller. Usage example:
cannam@128 643
cannam@128 644 unsigned long crc = 0L;
cannam@128 645
cannam@128 646 while (read_buffer(buffer, length) != EOF) {
cannam@128 647 crc = update_crc(crc, buffer, length);
cannam@128 648 }
cannam@128 649 if (crc != original_crc) error();
cannam@128 650 */
cannam@128 651 unsigned long update_crc(unsigned long crc,
cannam@128 652 unsigned char *buf, int len)
cannam@128 653 {
cannam@128 654 unsigned long c = crc ^ 0xffffffffL;
cannam@128 655 int n;
cannam@128 656
cannam@128 657 if (!crc_table_computed)
cannam@128 658 make_crc_table();
cannam@128 659 for (n = 0; n < len; n++) {
cannam@128 660 c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
cannam@128 661 }
cannam@128 662 return c ^ 0xffffffffL;
cannam@128 663 }
cannam@128 664
cannam@128 665 /* Return the CRC of the bytes buf[0..len-1]. */
cannam@128 666 unsigned long crc(unsigned char *buf, int len)
cannam@128 667 {
cannam@128 668 return update_crc(0L, buf, len);
cannam@128 669 }
cannam@128 670
cannam@128 671
cannam@128 672
cannam@128 673
cannam@128 674 Deutsch Informational [Page 12]
cannam@128 675