1 /*****************************************************************************/
\r
5 /* Decompression routines for the 'deflate' format */
\r
9 /* (C) 2000-2001 Piotr Fusik <fox@scene.pl> */
\r
11 /* This file is based on the zlib.h from 'zlib' general purpose compression */
\r
12 /* library, version 1.1.3, (C) 1995-1998 Jean-loup Gailly and Mark Adler. */
\r
14 /* Jean-loup Gailly Mark Adler */
\r
15 /* jloup@gzip.org madler@alumni.caltech.edu */
\r
17 /* This software is provided 'as-is', without any expressed or implied */
\r
18 /* warranty. In no event will the authors be held liable for any damages */
\r
19 /* arising from the use of this software. */
\r
21 /* Permission is granted to anyone to use this software for any purpose, */
\r
22 /* including commercial applications, and to alter it and redistribute it */
\r
23 /* freely, subject to the following restrictions: */
\r
25 /* 1. The origin of this software must not be misrepresented; you must not */
\r
26 /* claim that you wrote the original software. If you use this software */
\r
27 /* in a product, an acknowledgment in the product documentation would be */
\r
28 /* appreciated but is not required. */
\r
29 /* 2. Altered source versions must be plainly marked as such, and must not */
\r
30 /* be misrepresented as being the original software. */
\r
31 /* 3. This notice may not be removed or altered from any source */
\r
34 /*****************************************************************************/
\r
42 #define Z_DATA_ERROR (-3)
\r
43 /* Return codes for uncompress() */
\r
45 #define Z_DEFLATED 8
\r
46 /* The deflate compression method (the only one supported) */
\r
51 unsigned __fastcall__ inflatemem (char* dest, const char* source);
\r
53 Decompresses the source buffer into the destination buffer.
\r
54 Returns the size of the uncompressed data (number of bytes written starting
\r
57 This function expects data in the DEFLATE format, described in RFC
\r
58 (Request for Comments) 1951 in the file
\r
59 ftp://ds.internic.net/rfc/rfc1951.txt.
\r
61 This function does not exist in the original zlib. Its implementation
\r
62 using original zlib might be following:
\r
64 unsigned inflatemem (char* dest, const char* source)
\r
68 stream.next_in = (Bytef*) source;
\r
69 stream.avail_in = 65535;
\r
71 stream.next_out = dest;
\r
72 stream.avail_out = 65535;
\r
74 stream.zalloc = (alloc_func) 0;
\r
75 stream.zfree = (free_func) 0;
\r
77 inflateInit2(&stream, -MAX_WBITS);
\r
78 inflate(&stream, Z_FINISH);
\r
79 inflateEnd(&stream);
\r
81 return stream.total_out;
\r
86 int uncompress (char* dest, unsigned* destLen,
\r
87 const char* source, unsigned sourceLen);
\r
89 Original zlib description:
\r
91 Decompresses the source buffer into the destination buffer. sourceLen is
\r
92 the byte length of the source buffer. Upon entry, destLen is the total
\r
93 size of the destination buffer, which must be large enough to hold the
\r
94 entire uncompressed data. (The size of the uncompressed data must have
\r
95 been saved previously by the compressor and transmitted to the decompressor
\r
96 by some mechanism outside the scope of this compression library.)
\r
97 Upon exit, destLen is the actual size of the compressed buffer.
\r
98 This function can be used to decompress a whole file at once if the
\r
99 input file is mmap'ed.
\r
101 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
\r
102 enough memory, Z_BUF_ERROR if there was not enough room in the output
\r
103 buffer, or Z_DATA_ERROR if the input data was corrupted.
\r
105 Implementation notes:
\r
107 This function expects data in the ZLIB format, described in RFC 1950
\r
108 in the file ftp://ds.internic.net/rfc/rfc1950.txt. The ZLIB format is
\r
109 essentially the DEFLATE format plus a very small header and Adler-32
\r
112 Z_MEM_ERROR and Z_BUF_ERROR are never returned in this implementation.
\r
116 unsigned long __fastcall__ adler32 (unsigned long adler, const char* buf,
\r
120 Original zlib description:
\r
122 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
\r
123 return the updated checksum. If buf is NULL, this function returns
\r
124 the required initial value for the checksum.
\r
125 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
\r
126 much faster. Usage example:
\r
128 unsigned long adler = adler32(0L, Z_NULL, 0);
\r
130 while (read_buffer(buffer, length) != EOF) {
\r
131 adler = adler32(adler, buffer, length);
\r
133 if (adler != original_adler) error();
\r
135 Implementation notes:
\r
137 This function isn't actually much faster than crc32(), but it is smaller
\r
138 and does not use any lookup tables.
\r
142 unsigned long __fastcall__ crc32 (unsigned long crc, const char* buf,
\r
145 Original zlib description:
\r
147 Update a running crc with the bytes buf[0..len-1] and return the updated
\r
148 crc. If buf is NULL, this function returns the required initial value
\r
149 for the crc. Pre- and post-conditioning (one's complement) is performed
\r
150 within this function so it shouldn't be done by the application.
\r
153 unsigned long crc = crc32(0L, Z_NULL, 0);
\r
155 while (read_buffer(buffer, length) != EOF) {
\r
156 crc = crc32(crc, buffer, length);
\r
158 if (crc != original_crc) error();
\r
160 Implementation notes:
\r
162 This function uses statically allocated 1 KB lookup table. The table is
\r
163 initialised before it is used for the first time (that is, if buffer is
\r
164 NULL or length is zero, then the lookup table isn't initialised).
\r
168 /* end of zlib.h */
\r