Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / node_modules / gzip-js / test / test-files / spec.txt
1 GZIP file format specification version 4.3
2
3 Status of This Memo
4
5 This memo provides information for the Internet community. This memo does not specify an Internet standard of any kind. Distribution of this memo is unlimited.
6 IESG Note:
7
8 The IESG takes no position on the validity of any Intellectual Property Rights statements contained in this document.
9 Notices
10
11 Copyright © 1996 L. Peter Deutsch
12 Permission is granted to copy and distribute this document for any purpose and without charge, including translations into other languages and incorporation into compilations, provided that the copyright notice and this notice are preserved, and that any substantive changes or deletions from the original are clearly marked.
13
14 A pointer to the latest version of this and related documentation in HTML format can be found at the URL <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>.
15
16 Abstract
17
18 This specification defines a lossless compressed data format that is compatible with the widely used GZIP utility. The format includes a cyclic redundancy check value for detecting data corruption. The format presently uses the DEFLATE method of compression but can be easily extended to use other compression methods. The format can be implemented readily in a manner not covered by patents.
19 Table of Contents
20
21 1. Introduction
22 1.1. Purpose
23 1.2. Intended audience
24 1.3. Scope
25 1.4. Compliance
26 1.5. Definitions of terms and conventions used
27 1.6. Changes from previous versions
28 2. Detailed specification
29 2.1. Overall conventions
30 2.2. File format
31 2.3. Member format
32 2.3.1. Member header and trailer
33 2.3.1.1. Extra field
34 2.3.1.2. Compliance
35 3. References
36 4. Security Considerations
37 5. Acknowledgements
38 6. Author's Address
39 7. Appendix: Jean-Loup Gailly's gzip utility
40 8. Appendix: Sample CRC Code
41 1. Introduction
42
43 Purpose
44
45 The purpose of this specification is to define a lossless compressed data format that:
46
47 Is independent of CPU type, operating system, file system, and character set, and hence can be used for interchange;
48 Can compress or decompress a data stream (as opposed to a randomly accessible file) to produce another data stream, using only an a priori bounded amount of intermediate storage, and hence can be used in data communications or similar structures such as Unix filters;
49 Compresses data with efficiency comparable to the best currently available general-purpose compression methods, and in particular considerably better than the "compress" program;
50 Can be implemented readily in a manner not covered by patents, and hence can be practiced freely;
51 Is compatible with the file format produced by the current widely used gzip utility, in that conforming decompressors will be able to read data produced by the existing gzip compressor.
52 The data format defined by this specification does not attempt to:
53 Provide random access to compressed data;
54 Compress specialized data (e.g., raster graphics) as well as the best currently available specialized algorithms.
55 Intended audience
56
57 This specification is intended for use by implementors of software to compress data into gzip format and/or decompress data from gzip format.
58
59 The text of the specification assumes a basic background in programming at the level of bits and other primitive data representations.
60
61 Scope
62
63 The specification specifies a compression method and a file format (the latter assuming only that a file can store a sequence of arbitrary bytes). It does not specify any particular interface to a file system or anything about character sets or encodings (except for file names and comments, which are optional).
64
65 Compliance
66
67 Unless otherwise indicated below, a compliant decompressor must be able to accept and decompress any file that conforms to all the specifications presented here; a compliant compressor must produce files that conform to all the specifications presented here. The material in the appendices is not part of the specification per se and is not relevant to compliance.
68
69 Definitions of terms and conventions used
70
71 byte: 8 bits stored or transmitted as a unit (same as an octet). (For this specification, a byte is exactly 8 bits, even on machines which store a character on a number of bits different from 8.) See below for the numbering of bits within a byte.
72
73 1.6. Changes from previous versions
74
75 There have been no technical changes to the gzip format since version 4.1 of this specification. In version 4.2, some terminology was changed, and the sample CRC code was rewritten for clarity and to eliminate the requirement for the caller to do pre- and post-conditioning. Version 4.3 is a conversion of the specification to RFC style.
76
77 2. Detailed specification
78
79 Overall conventions
80
81 In the diagrams below, a box like this:
82 +---+
83 |   | <-- the vertical bars might be missing
84 +---+
85 represents one byte; a box like this:
86 +==============+
87 |              |
88 +==============+
89 represents a variable number of bytes.
90 Bytes stored within a computer do not have a "bit order", since they are always treated as a unit. However, a byte considered as an integer between 0 and 255 does have a most- and least-significant bit, and since we write numbers with the most-significant digit on the left, we also write bytes with the most-significant bit on the left. In the diagrams below, we number the bits of a byte so that bit 0 is the least-significant bit, i.e., the bits are numbered:
91
92 +--------+
93 |76543210|
94 +--------+
95 This document does not address the issue of the order in which bits of a byte are transmitted on a bit-sequential medium, since the data format described here is byte- rather than bit-oriented.
96
97 Within a computer, a number may occupy multiple bytes. All multi-byte numbers in the format described here are stored with the least-significant byte first (at the lower memory address). For example, the decimal number 520 is stored as:
98
99     0        1
100 +--------+--------+
101 |00001000|00000010|
102 +--------+--------+
103  ^        ^
104  |        |
105  |        + more significant byte = 2 x 256
106  + less significant byte = 8
107 File format
108
109 A gzip file consists of a series of "members" (compressed data sets). The format of each member is specified in the following section. The members simply appear one after another in the file, with no additional information before, between, or after them.
110
111 Member format
112
113 Each member has the following structure:
114 +---+---+---+---+---+---+---+---+---+---+
115 |ID1|ID2|CM |FLG|     MTIME     |XFL|OS | (more-->)
116 +---+---+---+---+---+---+---+---+---+---+
117 (if FLG.FEXTRA set)
118 +---+---+=================================+
119 | XLEN  |...XLEN bytes of "extra field"...| (more-->)
120 +---+---+=================================+
121 (if FLG.FNAME set)
122 +=========================================+
123 |...original file name, zero-terminated...| (more-->)
124 +=========================================+
125 (if FLG.FCOMMENT set)
126 +===================================+
127 |...file comment, zero-terminated...| (more-->)
128 +===================================+
129 (if FLG.FHCRC set)
130 +---+---+
131 | CRC16 |
132 +---+---+
133 +=======================+
134 |...compressed blocks...| (more-->)
135 +=======================+
136   0   1   2   3   4   5   6   7
137 +---+---+---+---+---+---+---+---+
138 |     CRC32     |     ISIZE     |
139 +---+---+---+---+---+---+---+---+
140 Member header and trailer
141
142 ID1 (IDentification 1)
143 ID2 (IDentification 2)
144 These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 (0x8b, \213), to identify the file as being in gzip format.
145 CM (Compression Method)
146 This identifies the compression method used in the file. CM = 0-7 are reserved. CM = 8 denotes the "deflate" compression method, which is the one customarily used by gzip and which is documented elsewhere.
147 FLG (FLaGs)
148 This flag byte is divided into individual bits as follows:
149 bit 0   FTEXT
150 bit 1   FHCRC
151 bit 2   FEXTRA
152 bit 3   FNAME
153 bit 4   FCOMMENT
154 bit 5   reserved
155 bit 6   reserved
156 bit 7   reserved
157 If FTEXT is set, the file is probably ASCII text. This is an optional indication, which the compressor may set by checking a small amount of the input data to see whether any non-ASCII characters are present. In case of doubt, FTEXT is cleared, indicating binary data. For systems which have different file formats for ascii text and binary data, the decompressor can use FTEXT to choose the appropriate format. We deliberately do not specify the algorithm used to set this bit, since a compressor always has the option of leaving it cleared and a decompressor always has the option of ignoring it and letting some other program handle issues of data conversion.
158
159 If FHCRC is set, a CRC16 for the gzip header is present, immediately before the compressed data. The CRC16 consists of the two least significant bytes of the CRC32 for all bytes of the gzip header up to and not including the CRC16. [The FHCRC bit was never set by versions of gzip up to 1.2.4, even though it was documented with a different meaning in gzip 1.2.4.]
160
161 If FEXTRA is set, optional extra fields are present, as described in a following section.
162
163 If FNAME is set, an original file name is present, terminated by a zero byte. The name must consist of ISO 8859-1 (LATIN-1) characters; on operating systems using EBCDIC or any other character set for file names, the name must be translated to the ISO LATIN-1 character set. This is the original name of the file being compressed, with any directory components removed, and, if the file being compressed is on a file system with case insensitive names, forced to lower case. There is no original file name if the data was compressed from a source other than a named file; for example, if the source was stdin on a Unix system, there is no file name.
164
165 If FCOMMENT is set, a zero-terminated file comment is present. This comment is not interpreted; it is only intended for human consumption. The comment must consist of ISO 8859-1 (LATIN-1) characters. Line breaks should be denoted by a single line feed character (10 decimal).
166
167 Reserved FLG bits must be zero.
168
169 MTIME (Modification TIME)
170 This gives the most recent modification time of the original file being compressed. The time is in Unix format, i.e., seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this may cause problems for MS-DOS and other systems that use local rather than Universal time.) If the compressed data did not come from a file, MTIME is set to the time at which compression started. MTIME = 0 means no time stamp is available.
171 XFL (eXtra FLags)
172 These flags are available for use by specific compression methods. The "deflate" method (CM = 8) sets these flags as follows:
173 XFL = 2 - compressor used maximum compression,
174           slowest algorithm
175 XFL = 4 - compressor used fastest algorithm
176 OS (Operating System)
177 This identifies the type of file system on which compression took place. This may be useful in determining end-of-line convention for text files. The currently defined values are as follows:
178   0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)
179   1 - Amiga
180   2 - VMS (or OpenVMS)
181   3 - Unix
182   4 - VM/CMS
183   5 - Atari TOS
184   6 - HPFS filesystem (OS/2, NT)
185   7 - Macintosh
186   8 - Z-System
187   9 - CP/M
188  10 - TOPS-20
189  11 - NTFS filesystem (NT)
190  12 - QDOS
191  13 - Acorn RISCOS
192 255 - unknown
193 XLEN (eXtra LENgth)
194 If FLG.FEXTRA is set, this gives the length of the optional extra field. See below for details.
195 CRC32 (CRC-32)
196 This contains a Cyclic Redundancy Check value of the uncompressed data computed according to CRC-32 algorithm used in the ISO 3309 standard and in section 8.1.1.6.2 of ITU-T recommendation V.42. (See http://www.iso.ch for ordering ISO documents. See gopher://info.itu.ch for an online version of ITU-T V.42.)
197 ISIZE (Input SIZE)
198 This contains the size of the original (uncompressed) input data modulo 2^32.
199 Extra field
200
201 If the FLG.FEXTRA bit is set, an "extra field" is present in the header, with total length XLEN bytes. It consists of a series of subfields, each of the form:
202
203 +---+---+---+---+==================================+
204 |SI1|SI2|  LEN  |... LEN bytes of subfield data ...|
205 +---+---+---+---+==================================+
206 SI1 and SI2 provide a subfield ID, typically two ASCII letters with some mnemonic value. Jean-Loup Gailly <jloup@gzip.org> is maintaining a registry of subfield IDs; please send him any subfield ID you wish to use. Subfield IDs with SI2 = 0 are reserved for future use. The following IDs are currently defined:
207 SI1         SI2         Data
208 ----------  ----------  ----
209 0x41 ('A')  0x70 ('P')  Apollo file type information
210 LEN gives the length of the subfield data, excluding the 4 initial bytes.
211 Compliance
212
213 A compliant compressor must produce files with correct ID1, ID2, CM, CRC32, and ISIZE, but may set all the other fields in the fixed-length part of the header to default values (255 for OS, 0 for all others). The compressor must set all reserved bits to zero.
214
215 A compliant decompressor must check ID1, ID2, and CM, and provide an error indication if any of these have incorrect values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC at least so it can skip over the optional fields if they are present. It need not examine any other part of the header or trailer; in particular, a decompressor may ignore FTEXT and OS and always produce binary output, and still be compliant. A compliant decompressor must give an error indication if any reserved bit is non-zero, since such a bit could indicate the presence of a new field that would cause subsequent data to be interpreted incorrectly.
216
217 3. References
218
219 [1] "Information Processing - 8-bit single-byte coded graphic character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). The ISO 8859-1 (Latin-1) character set is a superset of 7-bit ASCII. Files defining this character set are available as iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/
220
221 [2] ISO 3309
222
223 [3] ITU-T recommendation V.42
224
225 [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", available in ftp://ftp.uu.net/pub/archiving/zip/doc/
226
227 [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in ftp://prep.ai.mit.edu/pub/gnu/
228
229 [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table Look-Up", Communications of the ACM, 31(8), pp.1008-1013.
230
231 [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, pp.118-133.
232
233 [8] ftp://ftp.rocksoft.com/papers/crc_v3.txt, describing the CRC concept.
234
235 4. Security Considerations
236
237 Any data compression method involves the reduction of redundancy in the data. Consequently, any corruption of the data is likely to have severe effects and be difficult to correct. Uncompressed text, on the other hand, will probably still be readable despite the presence of some corrupted bytes. It is recommended that systems using this data format provide some means of validating the integrity of the compressed data, such as by setting and checking the CRC-32 check value.
238 5. Acknowledgements
239
240 Trademarks cited in this document are the property of their respective owners.
241 Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, the related software described in this specification. Glenn Randers-Pehrson converted this document to RFC and HTML format.
242
243 6. Author's Address
244
245 L. Peter Deutsch
246 Aladdin Enterprises
247 203 Santa Margarita Ave.
248 Menlo Park, CA 94025
249
250 Phone: (415) 322-0103 (AM only)
251 FAX:   (415) 322-1734
252 EMail: <ghost@aladdin.com>
253 Questions about the technical content of this specification can be sent by email to:
254 Jean-Loup Gailly <jloup@gzip.org> and
255 Mark Adler <madler@alumni.caltech.edu>
256 Editorial comments on this specification can be sent by email to:
257 L. Peter Deutsch <ghost@aladdin.com> and
258 Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
259 7. Appendix: Jean-Loup Gailly's gzip utility
260
261 The most widely used implementation of gzip compression, and the original documentation on which this specification is based, were created by Jean-Loup Gailly <jloup@gzip.org>. Since this implementation is a de facto standard, we mention some more of its features here. Again, the material in this section is not part of the specification per se, and implementations need not follow it to be compliant.
262 When compressing or decompressing a file, gzip preserves the protection, ownership, and modification time attributes on the local file system, since there is no provision for representing protection attributes in the gzip file format itself. Since the file format includes a modification time, the gzip decompressor provides a command line switch that assigns the modification time from the file, rather than the local modification time of the compressed input, to the decompressed output.
263
264 8. Appendix: Sample CRC Code
265
266 The following sample code represents a practical implementation of the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 for a formal specification.)
267 The sample code is in the ANSI C programming language. Non C users may find it easier to read with these hints:
268
269 &      Bitwise AND operator.
270 ^      Bitwise exclusive-OR operator.
271 >>     Bitwise right shift operator. When applied to an
272        unsigned quantity, as here, right shift inserts zero
273        bit(s) at the left.
274 !      Logical NOT operator.
275 ++     "n++" increments the variable n.
276 0xNNN  0x introduces a hexadecimal (base 16) constant.
277        Suffix L indicates a long value (at least 32 bits).
278
279 /* Table of CRCs of all 8-bit messages. */
280 unsigned long crc_table[256];
281
282 /* Flag: has the table been computed? Initially false. */
283 int crc_table_computed = 0;
284
285 /* Make the table for a fast CRC. */
286 void make_crc_table(void)
287 {
288   unsigned long c;
289   int n, k;
290
291   for (n = 0; n < 256; n++) {
292     c = (unsigned long) n;
293     for (k = 0; k < 8; k++) {
294       if (c & 1) {
295         c = 0xedb88320L ^ (c >> 1);
296       } else {
297         c = c >> 1;
298       }
299     }
300     crc_table[n] = c;
301   }
302   crc_table_computed = 1;
303 }
304
305 /*
306    Update a running crc with the bytes buf[0..len-1] and return
307  the updated crc. The crc should be initialized to zero. Pre- and
308  post-conditioning (one's complement) is performed within this
309  function so it shouldn't be done by the caller. Usage example:
310
311    unsigned long crc = 0L;
312
313    while (read_buffer(buffer, length) != EOF) {
314      crc = update_crc(crc, buffer, length);
315    }
316    if (crc != original_crc) error();
317 */
318 unsigned long update_crc(unsigned long crc,
319                 unsigned char *buf, int len)
320 {
321   unsigned long c = crc ^ 0xffffffffL;
322   int n;
323
324   if (!crc_table_computed)
325     make_crc_table();
326   for (n = 0; n < len; n++) {
327     c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
328   }
329   return c ^ 0xffffffffL;
330 }
331
332 /* Return the CRC of the bytes buf[0..len-1]. */
333 unsigned long crc(unsigned char *buf, int len)
334 {
335   return update_crc(0L, buf, len);
336 }