annotate src/zlib-1.2.8/doc/rfc1952.txt @ 65:a69c1527268d

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