annotate src/zlib-1.2.7/doc/rfc1952.txt @ 7:cd13f7cd9bc3

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