Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
michael@0 | 2 | version 1.0.4, Jul 24th, 1996. |
michael@0 | 3 | |
michael@0 | 4 | Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler |
michael@0 | 5 | |
michael@0 | 6 | This software is provided 'as-is', without any express or implied |
michael@0 | 7 | warranty. In no event will the authors be held liable for any damages |
michael@0 | 8 | arising from the use of this software. |
michael@0 | 9 | |
michael@0 | 10 | Permission is granted to anyone to use this software for any purpose, |
michael@0 | 11 | including commercial applications, and to alter it and redistribute it |
michael@0 | 12 | freely, subject to the following restrictions: |
michael@0 | 13 | |
michael@0 | 14 | 1. The origin of this software must not be misrepresented; you must not |
michael@0 | 15 | claim that you wrote the original software. If you use this software |
michael@0 | 16 | in a product, an acknowledgment in the product documentation would be |
michael@0 | 17 | appreciated but is not required. |
michael@0 | 18 | 2. Altered source versions must be plainly marked as such, and must not be |
michael@0 | 19 | misrepresented as being the original software. |
michael@0 | 20 | 3. This notice may not be removed or altered from any source distribution. |
michael@0 | 21 | |
michael@0 | 22 | Jean-loup Gailly Mark Adler |
michael@0 | 23 | gzip@prep.ai.mit.edu madler@alumni.caltech.edu |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | The data format used by the zlib library is described by RFCs (Request for |
michael@0 | 27 | Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt |
michael@0 | 28 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). |
michael@0 | 29 | */ |
michael@0 | 30 | /* This file was modified since it was taken from the zlib distribution */ |
michael@0 | 31 | |
michael@0 | 32 | #ifndef _ZLIB_H |
michael@0 | 33 | #define _ZLIB_H |
michael@0 | 34 | |
michael@0 | 35 | #ifdef __cplusplus |
michael@0 | 36 | extern "C" { |
michael@0 | 37 | #endif |
michael@0 | 38 | |
michael@0 | 39 | #ifdef MOZILLA_CLIENT |
michael@0 | 40 | #include "jzconf.h" |
michael@0 | 41 | #else |
michael@0 | 42 | #include "zconf.h" |
michael@0 | 43 | #endif |
michael@0 | 44 | |
michael@0 | 45 | #define ZLIB_VERSION "1.0.4" |
michael@0 | 46 | |
michael@0 | 47 | /* |
michael@0 | 48 | The 'zlib' compression library provides in-memory compression and |
michael@0 | 49 | decompression functions, including integrity checks of the uncompressed |
michael@0 | 50 | data. This version of the library supports only one compression method |
michael@0 | 51 | (deflation) but other algorithms may be added later and will have the same |
michael@0 | 52 | stream interface. |
michael@0 | 53 | |
michael@0 | 54 | For compression the application must provide the output buffer and |
michael@0 | 55 | may optionally provide the input buffer for optimization. For decompression, |
michael@0 | 56 | the application must provide the input buffer and may optionally provide |
michael@0 | 57 | the output buffer for optimization. |
michael@0 | 58 | |
michael@0 | 59 | Compression can be done in a single step if the buffers are large |
michael@0 | 60 | enough (for example if an input file is mmap'ed), or can be done by |
michael@0 | 61 | repeated calls of the compression function. In the latter case, the |
michael@0 | 62 | application must provide more input and/or consume the output |
michael@0 | 63 | (providing more output space) before each call. |
michael@0 | 64 | |
michael@0 | 65 | The library does not install any signal handler. It is recommended to |
michael@0 | 66 | add at least a handler for SIGSEGV when decompressing; the library checks |
michael@0 | 67 | the consistency of the input data whenever possible but may go nuts |
michael@0 | 68 | for some forms of corrupted input. |
michael@0 | 69 | */ |
michael@0 | 70 | |
michael@0 | 71 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
michael@0 | 72 | typedef void (*free_func) OF((voidpf opaque, voidpf address)); |
michael@0 | 73 | |
michael@0 | 74 | struct internal_state; |
michael@0 | 75 | |
michael@0 | 76 | typedef struct z_stream_s { |
michael@0 | 77 | Bytef *next_in; /* next input byte */ |
michael@0 | 78 | uInt avail_in; /* number of bytes available at next_in */ |
michael@0 | 79 | uLong total_in; /* total nb of input bytes read so far */ |
michael@0 | 80 | |
michael@0 | 81 | Bytef *next_out; /* next output byte should be put there */ |
michael@0 | 82 | uInt avail_out; /* remaining free space at next_out */ |
michael@0 | 83 | uLong total_out; /* total nb of bytes output so far */ |
michael@0 | 84 | |
michael@0 | 85 | char *msg; /* last error message, NULL if no error */ |
michael@0 | 86 | struct internal_state FAR *state; /* not visible by applications */ |
michael@0 | 87 | |
michael@0 | 88 | alloc_func zalloc; /* used to allocate the internal state */ |
michael@0 | 89 | free_func zfree; /* used to free the internal state */ |
michael@0 | 90 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
michael@0 | 91 | |
michael@0 | 92 | int data_type; /* best guess about the data type: ascii or binary */ |
michael@0 | 93 | uLong adler; /* adler32 value of the uncompressed data */ |
michael@0 | 94 | uLong reserved; /* reserved for future use */ |
michael@0 | 95 | } z_stream; |
michael@0 | 96 | |
michael@0 | 97 | typedef z_stream FAR *z_streamp; |
michael@0 | 98 | |
michael@0 | 99 | /* |
michael@0 | 100 | The application must update next_in and avail_in when avail_in has |
michael@0 | 101 | dropped to zero. It must update next_out and avail_out when avail_out |
michael@0 | 102 | has dropped to zero. The application must initialize zalloc, zfree and |
michael@0 | 103 | opaque before calling the init function. All other fields are set by the |
michael@0 | 104 | compression library and must not be updated by the application. |
michael@0 | 105 | |
michael@0 | 106 | The opaque value provided by the application will be passed as the first |
michael@0 | 107 | parameter for calls of zalloc and zfree. This can be useful for custom |
michael@0 | 108 | memory management. The compression library attaches no meaning to the |
michael@0 | 109 | opaque value. |
michael@0 | 110 | |
michael@0 | 111 | zalloc must return Z_NULL if there is not enough memory for the object. |
michael@0 | 112 | On 16-bit systems, the functions zalloc and zfree must be able to allocate |
michael@0 | 113 | exactly 65536 bytes, but will not be required to allocate more than this |
michael@0 | 114 | if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, |
michael@0 | 115 | pointers returned by zalloc for objects of exactly 65536 bytes *must* |
michael@0 | 116 | have their offset normalized to zero. The default allocation function |
michael@0 | 117 | provided by this library ensures this (see zutil.c). To reduce memory |
michael@0 | 118 | requirements and avoid any allocation of 64K objects, at the expense of |
michael@0 | 119 | compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). |
michael@0 | 120 | |
michael@0 | 121 | The fields total_in and total_out can be used for statistics or |
michael@0 | 122 | progress reports. After compression, total_in holds the total size of |
michael@0 | 123 | the uncompressed data and may be saved for use in the decompressor |
michael@0 | 124 | (particularly if the decompressor wants to decompress everything in |
michael@0 | 125 | a single step). |
michael@0 | 126 | */ |
michael@0 | 127 | |
michael@0 | 128 | /* constants */ |
michael@0 | 129 | |
michael@0 | 130 | #define Z_NO_FLUSH 0 |
michael@0 | 131 | #define Z_PARTIAL_FLUSH 1 |
michael@0 | 132 | #define Z_SYNC_FLUSH 2 |
michael@0 | 133 | #define Z_FULL_FLUSH 3 |
michael@0 | 134 | #define Z_FINISH 4 |
michael@0 | 135 | /* Allowed flush values; see deflate() below for details */ |
michael@0 | 136 | |
michael@0 | 137 | #define Z_OK 0 |
michael@0 | 138 | #define Z_STREAM_END 1 |
michael@0 | 139 | #define Z_NEED_DICT 2 |
michael@0 | 140 | #define Z_ERRNO (-1) |
michael@0 | 141 | #define Z_STREAM_ERROR (-2) |
michael@0 | 142 | #define Z_DATA_ERROR (-3) |
michael@0 | 143 | #define Z_MEM_ERROR (-4) |
michael@0 | 144 | #define Z_BUF_ERROR (-5) |
michael@0 | 145 | #define Z_VERSION_ERROR (-6) |
michael@0 | 146 | /* Return codes for the compression/decompression functions. Negative |
michael@0 | 147 | * values are errors, positive values are used for special but normal events. |
michael@0 | 148 | */ |
michael@0 | 149 | |
michael@0 | 150 | #define Z_NO_COMPRESSION 0 |
michael@0 | 151 | #define Z_BEST_SPEED 1 |
michael@0 | 152 | #define Z_BEST_COMPRESSION 9 |
michael@0 | 153 | #define Z_DEFAULT_COMPRESSION (-1) |
michael@0 | 154 | /* compression levels */ |
michael@0 | 155 | |
michael@0 | 156 | #define Z_FILTERED 1 |
michael@0 | 157 | #define Z_HUFFMAN_ONLY 2 |
michael@0 | 158 | #define Z_DEFAULT_STRATEGY 0 |
michael@0 | 159 | /* compression strategy; see deflateInit2() below for details */ |
michael@0 | 160 | |
michael@0 | 161 | #define Z_BINARY 0 |
michael@0 | 162 | #define Z_ASCII 1 |
michael@0 | 163 | #define Z_UNKNOWN 2 |
michael@0 | 164 | /* Possible values of the data_type field */ |
michael@0 | 165 | |
michael@0 | 166 | #define Z_DEFLATED 8 |
michael@0 | 167 | /* The deflate compression method (the only one supported in this version) */ |
michael@0 | 168 | |
michael@0 | 169 | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ |
michael@0 | 170 | |
michael@0 | 171 | #define zlib_version zlibVersion() |
michael@0 | 172 | /* for compatibility with versions < 1.0.2 */ |
michael@0 | 173 | |
michael@0 | 174 | /* basic functions */ |
michael@0 | 175 | |
michael@0 | 176 | #ifdef MOZILLA_CLIENT |
michael@0 | 177 | PR_EXTERN(const char *) zlibVersion (void); |
michael@0 | 178 | #else |
michael@0 | 179 | extern const char * EXPORT zlibVersion OF((void)); |
michael@0 | 180 | #endif |
michael@0 | 181 | /* The application can compare zlibVersion and ZLIB_VERSION for consistency. |
michael@0 | 182 | If the first character differs, the library code actually used is |
michael@0 | 183 | not compatible with the zlib.h header file used by the application. |
michael@0 | 184 | This check is automatically made by deflateInit and inflateInit. |
michael@0 | 185 | */ |
michael@0 | 186 | |
michael@0 | 187 | /* |
michael@0 | 188 | extern int EXPORT deflateInit OF((z_streamp strm, int level)); |
michael@0 | 189 | |
michael@0 | 190 | Initializes the internal stream state for compression. The fields |
michael@0 | 191 | zalloc, zfree and opaque must be initialized before by the caller. |
michael@0 | 192 | If zalloc and zfree are set to Z_NULL, deflateInit updates them to |
michael@0 | 193 | use default allocation functions. |
michael@0 | 194 | |
michael@0 | 195 | The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: |
michael@0 | 196 | 1 gives best speed, 9 gives best compression, 0 gives no compression at |
michael@0 | 197 | all (the input data is simply copied a block at a time). |
michael@0 | 198 | Z_DEFAULT_COMPRESSION requests a default compromise between speed and |
michael@0 | 199 | compression (currently equivalent to level 6). |
michael@0 | 200 | |
michael@0 | 201 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not |
michael@0 | 202 | enough memory, Z_STREAM_ERROR if level is not a valid compression level, |
michael@0 | 203 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible |
michael@0 | 204 | with the version assumed by the caller (ZLIB_VERSION). |
michael@0 | 205 | msg is set to null if there is no error message. deflateInit does not |
michael@0 | 206 | perform any compression: this will be done by deflate(). |
michael@0 | 207 | */ |
michael@0 | 208 | |
michael@0 | 209 | |
michael@0 | 210 | #ifdef MOZILLA_CLIENT |
michael@0 | 211 | PR_EXTERN(int) deflate (z_streamp strm, int flush); |
michael@0 | 212 | #else |
michael@0 | 213 | extern int EXPORT deflate OF((z_streamp strm, int flush)); |
michael@0 | 214 | #endif |
michael@0 | 215 | /* |
michael@0 | 216 | Performs one or both of the following actions: |
michael@0 | 217 | |
michael@0 | 218 | - Compress more input starting at next_in and update next_in and avail_in |
michael@0 | 219 | accordingly. If not all input can be processed (because there is not |
michael@0 | 220 | enough room in the output buffer), next_in and avail_in are updated and |
michael@0 | 221 | processing will resume at this point for the next call of deflate(). |
michael@0 | 222 | |
michael@0 | 223 | - Provide more output starting at next_out and update next_out and avail_out |
michael@0 | 224 | accordingly. This action is forced if the parameter flush is non zero. |
michael@0 | 225 | Forcing flush frequently degrades the compression ratio, so this parameter |
michael@0 | 226 | should be set only when necessary (in interactive applications). |
michael@0 | 227 | Some output may be provided even if flush is not set. |
michael@0 | 228 | |
michael@0 | 229 | Before the call of deflate(), the application should ensure that at least |
michael@0 | 230 | one of the actions is possible, by providing more input and/or consuming |
michael@0 | 231 | more output, and updating avail_in or avail_out accordingly; avail_out |
michael@0 | 232 | should never be zero before the call. The application can consume the |
michael@0 | 233 | compressed output when it wants, for example when the output buffer is full |
michael@0 | 234 | (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK |
michael@0 | 235 | and with zero avail_out, it must be called again after making room in the |
michael@0 | 236 | output buffer because there might be more output pending. |
michael@0 | 237 | |
michael@0 | 238 | If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression |
michael@0 | 239 | block is terminated and flushed to the output buffer so that the |
michael@0 | 240 | decompressor can get all input data available so far. For method 9, a future |
michael@0 | 241 | variant on method 8, the current block will be flushed but not terminated. |
michael@0 | 242 | Z_SYNC_FLUSH has the same effect as partial flush except that the compressed |
michael@0 | 243 | output is byte aligned (the compressor can clear its internal bit buffer) |
michael@0 | 244 | and the current block is always terminated; this can be useful if the |
michael@0 | 245 | compressor has to be restarted from scratch after an interruption (in which |
michael@0 | 246 | case the internal state of the compressor may be lost). |
michael@0 | 247 | If flush is set to Z_FULL_FLUSH, the compression block is terminated, a |
michael@0 | 248 | special marker is output and the compression dictionary is discarded; this |
michael@0 | 249 | is useful to allow the decompressor to synchronize if one compressed block |
michael@0 | 250 | has been damaged (see inflateSync below). Flushing degrades compression and |
michael@0 | 251 | so should be used only when necessary. Using Z_FULL_FLUSH too often can |
michael@0 | 252 | seriously degrade the compression. If deflate returns with avail_out == 0, |
michael@0 | 253 | this function must be called again with the same value of the flush |
michael@0 | 254 | parameter and more output space (updated avail_out), until the flush is |
michael@0 | 255 | complete (deflate returns with non-zero avail_out). |
michael@0 | 256 | |
michael@0 | 257 | If the parameter flush is set to Z_FINISH, pending input is processed, |
michael@0 | 258 | pending output is flushed and deflate returns with Z_STREAM_END if there |
michael@0 | 259 | was enough output space; if deflate returns with Z_OK, this function must be |
michael@0 | 260 | called again with Z_FINISH and more output space (updated avail_out) but no |
michael@0 | 261 | more input data, until it returns with Z_STREAM_END or an error. After |
michael@0 | 262 | deflate has returned Z_STREAM_END, the only possible operations on the |
michael@0 | 263 | stream are deflateReset or deflateEnd. |
michael@0 | 264 | |
michael@0 | 265 | Z_FINISH can be used immediately after deflateInit if all the compression |
michael@0 | 266 | is to be done in a single step. In this case, avail_out must be at least |
michael@0 | 267 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return |
michael@0 | 268 | Z_STREAM_END, then it must be called again as described above. |
michael@0 | 269 | |
michael@0 | 270 | deflate() may update data_type if it can make a good guess about |
michael@0 | 271 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered |
michael@0 | 272 | binary. This field is only for information purposes and does not affect |
michael@0 | 273 | the compression algorithm in any manner. |
michael@0 | 274 | |
michael@0 | 275 | deflate() returns Z_OK if some progress has been made (more input |
michael@0 | 276 | processed or more output produced), Z_STREAM_END if all input has been |
michael@0 | 277 | consumed and all output has been produced (only when flush is set to |
michael@0 | 278 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example |
michael@0 | 279 | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible. |
michael@0 | 280 | */ |
michael@0 | 281 | |
michael@0 | 282 | |
michael@0 | 283 | #ifdef MOZILLA_CLIENT |
michael@0 | 284 | PR_EXTERN(int) deflateEnd (z_streamp strm); |
michael@0 | 285 | #else |
michael@0 | 286 | extern int EXPORT deflateEnd OF((z_streamp strm)); |
michael@0 | 287 | #endif |
michael@0 | 288 | /* |
michael@0 | 289 | All dynamically allocated data structures for this stream are freed. |
michael@0 | 290 | This function discards any unprocessed input and does not flush any |
michael@0 | 291 | pending output. |
michael@0 | 292 | |
michael@0 | 293 | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the |
michael@0 | 294 | stream state was inconsistent, Z_DATA_ERROR if the stream was freed |
michael@0 | 295 | prematurely (some input or output was discarded). In the error case, |
michael@0 | 296 | msg may be set but then points to a static string (which must not be |
michael@0 | 297 | deallocated). |
michael@0 | 298 | */ |
michael@0 | 299 | |
michael@0 | 300 | |
michael@0 | 301 | /* |
michael@0 | 302 | extern int EXPORT inflateInit OF((z_streamp strm)); |
michael@0 | 303 | |
michael@0 | 304 | Initializes the internal stream state for decompression. The fields |
michael@0 | 305 | zalloc, zfree and opaque must be initialized before by the caller. If |
michael@0 | 306 | zalloc and zfree are set to Z_NULL, inflateInit updates them to use default |
michael@0 | 307 | allocation functions. |
michael@0 | 308 | |
michael@0 | 309 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not |
michael@0 | 310 | enough memory, Z_VERSION_ERROR if the zlib library version is incompatible |
michael@0 | 311 | with the version assumed by the caller. msg is set to null if there is no |
michael@0 | 312 | error message. inflateInit does not perform any decompression: this will be |
michael@0 | 313 | done by inflate(). |
michael@0 | 314 | */ |
michael@0 | 315 | |
michael@0 | 316 | |
michael@0 | 317 | #ifdef MOZILLA_CLIENT |
michael@0 | 318 | PR_EXTERN(int) inflate (z_streamp strm, int flush); |
michael@0 | 319 | #else |
michael@0 | 320 | extern int EXPORT inflate OF((z_streamp strm, int flush)); |
michael@0 | 321 | #endif |
michael@0 | 322 | /* |
michael@0 | 323 | Performs one or both of the following actions: |
michael@0 | 324 | |
michael@0 | 325 | - Decompress more input starting at next_in and update next_in and avail_in |
michael@0 | 326 | accordingly. If not all input can be processed (because there is not |
michael@0 | 327 | enough room in the output buffer), next_in is updated and processing |
michael@0 | 328 | will resume at this point for the next call of inflate(). |
michael@0 | 329 | |
michael@0 | 330 | - Provide more output starting at next_out and update next_out and avail_out |
michael@0 | 331 | accordingly. inflate() provides as much output as possible, until there |
michael@0 | 332 | is no more input data or no more space in the output buffer (see below |
michael@0 | 333 | about the flush parameter). |
michael@0 | 334 | |
michael@0 | 335 | Before the call of inflate(), the application should ensure that at least |
michael@0 | 336 | one of the actions is possible, by providing more input and/or consuming |
michael@0 | 337 | more output, and updating the next_* and avail_* values accordingly. |
michael@0 | 338 | The application can consume the uncompressed output when it wants, for |
michael@0 | 339 | example when the output buffer is full (avail_out == 0), or after each |
michael@0 | 340 | call of inflate(). If inflate returns Z_OK and with zero avail_out, it |
michael@0 | 341 | must be called again after making room in the output buffer because there |
michael@0 | 342 | might be more output pending. |
michael@0 | 343 | |
michael@0 | 344 | If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much |
michael@0 | 345 | output as possible to the output buffer. The flushing behavior of inflate is |
michael@0 | 346 | not specified for values of the flush parameter other than Z_PARTIAL_FLUSH |
michael@0 | 347 | and Z_FINISH, but the current implementation actually flushes as much output |
michael@0 | 348 | as possible anyway. |
michael@0 | 349 | |
michael@0 | 350 | inflate() should normally be called until it returns Z_STREAM_END or an |
michael@0 | 351 | error. However if all decompression is to be performed in a single step |
michael@0 | 352 | (a single call of inflate), the parameter flush should be set to |
michael@0 | 353 | Z_FINISH. In this case all pending input is processed and all pending |
michael@0 | 354 | output is flushed; avail_out must be large enough to hold all the |
michael@0 | 355 | uncompressed data. (The size of the uncompressed data may have been saved |
michael@0 | 356 | by the compressor for this purpose.) The next operation on this stream must |
michael@0 | 357 | be inflateEnd to deallocate the decompression state. The use of Z_FINISH |
michael@0 | 358 | is never required, but can be used to inform inflate that a faster routine |
michael@0 | 359 | may be used for the single inflate() call. |
michael@0 | 360 | |
michael@0 | 361 | inflate() returns Z_OK if some progress has been made (more input |
michael@0 | 362 | processed or more output produced), Z_STREAM_END if the end of the |
michael@0 | 363 | compressed data has been reached and all uncompressed output has been |
michael@0 | 364 | produced, Z_NEED_DICT if a preset dictionary is needed at this point (see |
michael@0 | 365 | inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted, |
michael@0 | 366 | Z_STREAM_ERROR if the stream structure was inconsistent (for example if |
michael@0 | 367 | next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, |
michael@0 | 368 | Z_BUF_ERROR if no progress is possible or if there was not enough room in |
michael@0 | 369 | the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the |
michael@0 | 370 | application may then call inflateSync to look for a good compression block. |
michael@0 | 371 | In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the |
michael@0 | 372 | dictionary chosen by the compressor. |
michael@0 | 373 | */ |
michael@0 | 374 | |
michael@0 | 375 | |
michael@0 | 376 | #ifdef MOZILLA_CLIENT |
michael@0 | 377 | PR_EXTERN(int) inflateEnd (z_streamp strm); |
michael@0 | 378 | #else |
michael@0 | 379 | extern int EXPORT inflateEnd OF((z_streamp strm)); |
michael@0 | 380 | #endif |
michael@0 | 381 | /* |
michael@0 | 382 | All dynamically allocated data structures for this stream are freed. |
michael@0 | 383 | This function discards any unprocessed input and does not flush any |
michael@0 | 384 | pending output. |
michael@0 | 385 | |
michael@0 | 386 | inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state |
michael@0 | 387 | was inconsistent. In the error case, msg may be set but then points to a |
michael@0 | 388 | static string (which must not be deallocated). |
michael@0 | 389 | */ |
michael@0 | 390 | |
michael@0 | 391 | /* Advanced functions */ |
michael@0 | 392 | |
michael@0 | 393 | /* |
michael@0 | 394 | The following functions are needed only in some special applications. |
michael@0 | 395 | */ |
michael@0 | 396 | |
michael@0 | 397 | /* |
michael@0 | 398 | extern int EXPORT deflateInit2 OF((z_streamp strm, |
michael@0 | 399 | int level, |
michael@0 | 400 | int method, |
michael@0 | 401 | int windowBits, |
michael@0 | 402 | int memLevel, |
michael@0 | 403 | int strategy)); |
michael@0 | 404 | |
michael@0 | 405 | This is another version of deflateInit with more compression options. The |
michael@0 | 406 | fields next_in, zalloc, zfree and opaque must be initialized before by |
michael@0 | 407 | the caller. |
michael@0 | 408 | |
michael@0 | 409 | The method parameter is the compression method. It must be Z_DEFLATED in |
michael@0 | 410 | this version of the library. (Method 9 will allow a 64K history buffer and |
michael@0 | 411 | partial block flushes.) |
michael@0 | 412 | |
michael@0 | 413 | The windowBits parameter is the base two logarithm of the window size |
michael@0 | 414 | (the size of the history buffer). It should be in the range 8..15 for this |
michael@0 | 415 | version of the library (the value 16 will be allowed for method 9). Larger |
michael@0 | 416 | values of this parameter result in better compression at the expense of |
michael@0 | 417 | memory usage. The default value is 15 if deflateInit is used instead. |
michael@0 | 418 | |
michael@0 | 419 | The memLevel parameter specifies how much memory should be allocated |
michael@0 | 420 | for the internal compression state. memLevel=1 uses minimum memory but |
michael@0 | 421 | is slow and reduces compression ratio; memLevel=9 uses maximum memory |
michael@0 | 422 | for optimal speed. The default value is 8. See zconf.h for total memory |
michael@0 | 423 | usage as a function of windowBits and memLevel. |
michael@0 | 424 | |
michael@0 | 425 | The strategy parameter is used to tune the compression algorithm. Use the |
michael@0 | 426 | value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a |
michael@0 | 427 | filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no |
michael@0 | 428 | string match). Filtered data consists mostly of small values with a |
michael@0 | 429 | somewhat random distribution. In this case, the compression algorithm is |
michael@0 | 430 | tuned to compress them better. The effect of Z_FILTERED is to force more |
michael@0 | 431 | Huffman coding and less string matching; it is somewhat intermediate |
michael@0 | 432 | between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects |
michael@0 | 433 | the compression ratio but not the correctness of the compressed output even |
michael@0 | 434 | if it is not set appropriately. |
michael@0 | 435 | |
michael@0 | 436 | If next_in is not null, the library will use this buffer to hold also |
michael@0 | 437 | some history information; the buffer must either hold the entire input |
michael@0 | 438 | data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in |
michael@0 | 439 | is null, the library will allocate its own history buffer (and leave next_in |
michael@0 | 440 | null). next_out need not be provided here but must be provided by the |
michael@0 | 441 | application for the next call of deflate(). |
michael@0 | 442 | |
michael@0 | 443 | If the history buffer is provided by the application, next_in must |
michael@0 | 444 | must never be changed by the application since the compressor maintains |
michael@0 | 445 | information inside this buffer from call to call; the application |
michael@0 | 446 | must provide more input only by increasing avail_in. next_in is always |
michael@0 | 447 | reset by the library in this case. |
michael@0 | 448 | |
michael@0 | 449 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was |
michael@0 | 450 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as |
michael@0 | 451 | an invalid method). msg is set to null if there is no error message. |
michael@0 | 452 | deflateInit2 does not perform any compression: this will be done by |
michael@0 | 453 | deflate(). |
michael@0 | 454 | */ |
michael@0 | 455 | |
michael@0 | 456 | #ifdef MOZILLA_CLIENT |
michael@0 | 457 | PR_EXTERN(int) deflateSetDictionary (z_streamp strm, |
michael@0 | 458 | const Bytef *dictionary, |
michael@0 | 459 | uInt dictLength); |
michael@0 | 460 | #else |
michael@0 | 461 | extern int EXPORT deflateSetDictionary OF((z_streamp strm, |
michael@0 | 462 | const Bytef *dictionary, |
michael@0 | 463 | uInt dictLength)); |
michael@0 | 464 | #endif |
michael@0 | 465 | /* |
michael@0 | 466 | Initializes the compression dictionary (history buffer) from the given |
michael@0 | 467 | byte sequence without producing any compressed output. This function must |
michael@0 | 468 | be called immediately after deflateInit or deflateInit2, before any call |
michael@0 | 469 | of deflate. The compressor and decompressor must use exactly the same |
michael@0 | 470 | dictionary (see inflateSetDictionary). |
michael@0 | 471 | The dictionary should consist of strings (byte sequences) that are likely |
michael@0 | 472 | to be encountered later in the data to be compressed, with the most commonly |
michael@0 | 473 | used strings preferably put towards the end of the dictionary. Using a |
michael@0 | 474 | dictionary is most useful when the data to be compressed is short and |
michael@0 | 475 | can be predicted with good accuracy; the data can then be compressed better |
michael@0 | 476 | than with the default empty dictionary. In this version of the library, |
michael@0 | 477 | only the last 32K bytes of the dictionary are used. |
michael@0 | 478 | Upon return of this function, strm->adler is set to the Adler32 value |
michael@0 | 479 | of the dictionary; the decompressor may later use this value to determine |
michael@0 | 480 | which dictionary has been used by the compressor. (The Adler32 value |
michael@0 | 481 | applies to the whole dictionary even if only a subset of the dictionary is |
michael@0 | 482 | actually used by the compressor.) |
michael@0 | 483 | |
michael@0 | 484 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a |
michael@0 | 485 | parameter is invalid (such as NULL dictionary) or the stream state |
michael@0 | 486 | is inconsistent (for example if deflate has already been called for this |
michael@0 | 487 | stream). deflateSetDictionary does not perform any compression: this will |
michael@0 | 488 | be done by deflate(). |
michael@0 | 489 | */ |
michael@0 | 490 | |
michael@0 | 491 | #ifdef MOZILLA_CLIENT |
michael@0 | 492 | PR_EXTERN(int) deflateCopy (z_streamp dest, z_streamp source); |
michael@0 | 493 | #else |
michael@0 | 494 | extern int EXPORT deflateCopy OF((z_streamp dest, z_streamp source)); |
michael@0 | 495 | #endif |
michael@0 | 496 | /* |
michael@0 | 497 | Sets the destination stream as a complete copy of the source stream. If |
michael@0 | 498 | the source stream is using an application-supplied history buffer, a new |
michael@0 | 499 | buffer is allocated for the destination stream. The compressed output |
michael@0 | 500 | buffer is always application-supplied. It's the responsibility of the |
michael@0 | 501 | application to provide the correct values of next_out and avail_out for the |
michael@0 | 502 | next call of deflate. |
michael@0 | 503 | |
michael@0 | 504 | This function can be useful when several compression strategies will be |
michael@0 | 505 | tried, for example when there are several ways of pre-processing the input |
michael@0 | 506 | data with a filter. The streams that will be discarded should then be freed |
michael@0 | 507 | by calling deflateEnd. Note that deflateCopy duplicates the internal |
michael@0 | 508 | compression state which can be quite large, so this strategy is slow and |
michael@0 | 509 | can consume lots of memory. |
michael@0 | 510 | |
michael@0 | 511 | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not |
michael@0 | 512 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent |
michael@0 | 513 | (such as zalloc being NULL). msg is left unchanged in both source and |
michael@0 | 514 | destination. |
michael@0 | 515 | */ |
michael@0 | 516 | |
michael@0 | 517 | #ifdef MOZILLA_CLIENT |
michael@0 | 518 | PR_EXTERN(int) deflateReset (z_streamp strm); |
michael@0 | 519 | #else |
michael@0 | 520 | extern int EXPORT deflateReset OF((z_streamp strm)); |
michael@0 | 521 | #endif |
michael@0 | 522 | /* |
michael@0 | 523 | This function is equivalent to deflateEnd followed by deflateInit, |
michael@0 | 524 | but does not free and reallocate all the internal compression state. |
michael@0 | 525 | The stream will keep the same compression level and any other attributes |
michael@0 | 526 | that may have been set by deflateInit2. |
michael@0 | 527 | |
michael@0 | 528 | deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
michael@0 | 529 | stream state was inconsistent (such as zalloc or state being NULL). |
michael@0 | 530 | */ |
michael@0 | 531 | |
michael@0 | 532 | #ifdef MOZILLA_CLIENT |
michael@0 | 533 | PR_EXTERN(int) deflateParams (z_streamp strm, int level, int strategy); |
michael@0 | 534 | #else |
michael@0 | 535 | extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); |
michael@0 | 536 | #endif |
michael@0 | 537 | /* |
michael@0 | 538 | Dynamically update the compression level and compression strategy. |
michael@0 | 539 | This can be used to switch between compression and straight copy of |
michael@0 | 540 | the input data, or to switch to a different kind of input data requiring |
michael@0 | 541 | a different strategy. If the compression level is changed, the input |
michael@0 | 542 | available so far is compressed with the old level (and may be flushed); |
michael@0 | 543 | the new level will take effect only at the next call of deflate(). |
michael@0 | 544 | |
michael@0 | 545 | Before the call of deflateParams, the stream state must be set as for |
michael@0 | 546 | a call of deflate(), since the currently available input may have to |
michael@0 | 547 | be compressed and flushed. In particular, strm->avail_out must be non-zero. |
michael@0 | 548 | |
michael@0 | 549 | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source |
michael@0 | 550 | stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR |
michael@0 | 551 | if strm->avail_out was zero. |
michael@0 | 552 | */ |
michael@0 | 553 | |
michael@0 | 554 | /* |
michael@0 | 555 | extern int EXPORT inflateInit2 OF((z_streamp strm, |
michael@0 | 556 | int windowBits)); |
michael@0 | 557 | |
michael@0 | 558 | This is another version of inflateInit with more compression options. The |
michael@0 | 559 | fields next_out, zalloc, zfree and opaque must be initialized before by |
michael@0 | 560 | the caller. |
michael@0 | 561 | |
michael@0 | 562 | The windowBits parameter is the base two logarithm of the maximum window |
michael@0 | 563 | size (the size of the history buffer). It should be in the range 8..15 for |
michael@0 | 564 | this version of the library (the value 16 will be allowed soon). The |
michael@0 | 565 | default value is 15 if inflateInit is used instead. If a compressed stream |
michael@0 | 566 | with a larger window size is given as input, inflate() will return with |
michael@0 | 567 | the error code Z_DATA_ERROR instead of trying to allocate a larger window. |
michael@0 | 568 | |
michael@0 | 569 | If next_out is not null, the library will use this buffer for the history |
michael@0 | 570 | buffer; the buffer must either be large enough to hold the entire output |
michael@0 | 571 | data, or have at least 1<<windowBits bytes. If next_out is null, the |
michael@0 | 572 | library will allocate its own buffer (and leave next_out null). next_in |
michael@0 | 573 | need not be provided here but must be provided by the application for the |
michael@0 | 574 | next call of inflate(). |
michael@0 | 575 | |
michael@0 | 576 | If the history buffer is provided by the application, next_out must |
michael@0 | 577 | never be changed by the application since the decompressor maintains |
michael@0 | 578 | history information inside this buffer from call to call; the application |
michael@0 | 579 | can only reset next_out to the beginning of the history buffer when |
michael@0 | 580 | avail_out is zero and all output has been consumed. |
michael@0 | 581 | |
michael@0 | 582 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was |
michael@0 | 583 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as |
michael@0 | 584 | windowBits < 8). msg is set to null if there is no error message. |
michael@0 | 585 | inflateInit2 does not perform any decompression: this will be done by |
michael@0 | 586 | inflate(). |
michael@0 | 587 | */ |
michael@0 | 588 | |
michael@0 | 589 | #ifdef MOZILLA_CLIENT |
michael@0 | 590 | PR_EXTERN(int) inflateSetDictionary (z_streamp strm, |
michael@0 | 591 | const Bytef *dictionary, |
michael@0 | 592 | uInt dictLength); |
michael@0 | 593 | #else |
michael@0 | 594 | extern int EXPORT inflateSetDictionary OF((z_streamp strm, |
michael@0 | 595 | const Bytef *dictionary, |
michael@0 | 596 | uInt dictLength)); |
michael@0 | 597 | #endif |
michael@0 | 598 | /* |
michael@0 | 599 | Initializes the decompression dictionary (history buffer) from the given |
michael@0 | 600 | uncompressed byte sequence. This function must be called immediately after |
michael@0 | 601 | a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen |
michael@0 | 602 | by the compressor can be determined from the Adler32 value returned by this |
michael@0 | 603 | call of inflate. The compressor and decompressor must use exactly the same |
michael@0 | 604 | dictionary (see deflateSetDictionary). |
michael@0 | 605 | |
michael@0 | 606 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
michael@0 | 607 | parameter is invalid (such as NULL dictionary) or the stream state is |
michael@0 | 608 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the |
michael@0 | 609 | expected one (incorrect Adler32 value). inflateSetDictionary does not |
michael@0 | 610 | perform any decompression: this will be done by subsequent calls of |
michael@0 | 611 | inflate(). |
michael@0 | 612 | */ |
michael@0 | 613 | |
michael@0 | 614 | #ifdef MOZILLA_CLIENT |
michael@0 | 615 | PR_EXTERN(int) inflateSync (z_streamp strm); |
michael@0 | 616 | #else |
michael@0 | 617 | extern int EXPORT inflateSync OF((z_streamp strm)); |
michael@0 | 618 | #endif |
michael@0 | 619 | /* |
michael@0 | 620 | Skips invalid compressed data until the special marker (see deflate() |
michael@0 | 621 | above) can be found, or until all available input is skipped. No output |
michael@0 | 622 | is provided. |
michael@0 | 623 | |
michael@0 | 624 | inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR |
michael@0 | 625 | if no more input was provided, Z_DATA_ERROR if no marker has been found, |
michael@0 | 626 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success |
michael@0 | 627 | case, the application may save the current current value of total_in which |
michael@0 | 628 | indicates where valid compressed data was found. In the error case, the |
michael@0 | 629 | application may repeatedly call inflateSync, providing more input each time, |
michael@0 | 630 | until success or end of the input data. |
michael@0 | 631 | */ |
michael@0 | 632 | |
michael@0 | 633 | #ifdef MOZILLA_CLIENT |
michael@0 | 634 | PR_EXTERN(int) inflateReset (z_streamp strm); |
michael@0 | 635 | #else |
michael@0 | 636 | extern int EXPORT inflateReset OF((z_streamp strm)); |
michael@0 | 637 | #endif |
michael@0 | 638 | /* |
michael@0 | 639 | This function is equivalent to inflateEnd followed by inflateInit, |
michael@0 | 640 | but does not free and reallocate all the internal decompression state. |
michael@0 | 641 | The stream will keep attributes that may have been set by inflateInit2. |
michael@0 | 642 | |
michael@0 | 643 | inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
michael@0 | 644 | stream state was inconsistent (such as zalloc or state being NULL). |
michael@0 | 645 | */ |
michael@0 | 646 | |
michael@0 | 647 | |
michael@0 | 648 | /* utility functions */ |
michael@0 | 649 | |
michael@0 | 650 | /* |
michael@0 | 651 | The following utility functions are implemented on top of the |
michael@0 | 652 | basic stream-oriented functions. To simplify the interface, some |
michael@0 | 653 | default options are assumed (compression level, window size, |
michael@0 | 654 | standard memory allocation functions). The source code of these |
michael@0 | 655 | utility functions can easily be modified if you need special options. |
michael@0 | 656 | */ |
michael@0 | 657 | |
michael@0 | 658 | #ifdef MOZILLA_CLIENT |
michael@0 | 659 | PR_EXTERN(int) compress (Bytef *dest, uLongf *destLen, |
michael@0 | 660 | const Bytef *source, uLong sourceLen); |
michael@0 | 661 | #else |
michael@0 | 662 | extern int EXPORT compress OF((Bytef *dest, uLongf *destLen, |
michael@0 | 663 | const Bytef *source, uLong sourceLen)); |
michael@0 | 664 | #endif |
michael@0 | 665 | /* |
michael@0 | 666 | Compresses the source buffer into the destination buffer. sourceLen is |
michael@0 | 667 | the byte length of the source buffer. Upon entry, destLen is the total |
michael@0 | 668 | size of the destination buffer, which must be at least 0.1% larger than |
michael@0 | 669 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the |
michael@0 | 670 | compressed buffer. |
michael@0 | 671 | This function can be used to compress a whole file at once if the |
michael@0 | 672 | input file is mmap'ed. |
michael@0 | 673 | compress returns Z_OK if success, Z_MEM_ERROR if there was not |
michael@0 | 674 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
michael@0 | 675 | buffer. |
michael@0 | 676 | */ |
michael@0 | 677 | |
michael@0 | 678 | #ifdef MOZILLA_CLIENT |
michael@0 | 679 | PR_EXTERN(int) uncompress (Bytef *dest, uLongf *destLen, |
michael@0 | 680 | const Bytef *source, uLong sourceLen); |
michael@0 | 681 | #else |
michael@0 | 682 | extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen, |
michael@0 | 683 | const Bytef *source, uLong sourceLen)); |
michael@0 | 684 | #endif |
michael@0 | 685 | /* |
michael@0 | 686 | Decompresses the source buffer into the destination buffer. sourceLen is |
michael@0 | 687 | the byte length of the source buffer. Upon entry, destLen is the total |
michael@0 | 688 | size of the destination buffer, which must be large enough to hold the |
michael@0 | 689 | entire uncompressed data. (The size of the uncompressed data must have |
michael@0 | 690 | been saved previously by the compressor and transmitted to the decompressor |
michael@0 | 691 | by some mechanism outside the scope of this compression library.) |
michael@0 | 692 | Upon exit, destLen is the actual size of the compressed buffer. |
michael@0 | 693 | This function can be used to decompress a whole file at once if the |
michael@0 | 694 | input file is mmap'ed. |
michael@0 | 695 | |
michael@0 | 696 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
michael@0 | 697 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
michael@0 | 698 | buffer, or Z_DATA_ERROR if the input data was corrupted. |
michael@0 | 699 | */ |
michael@0 | 700 | |
michael@0 | 701 | |
michael@0 | 702 | typedef voidp gzFile; |
michael@0 | 703 | |
michael@0 | 704 | #ifdef MOZILLA_CLIENT |
michael@0 | 705 | PR_EXTERN(gzFile) gzopen (const char *path, const char *mode); |
michael@0 | 706 | #else |
michael@0 | 707 | extern gzFile EXPORT gzopen OF((const char *path, const char *mode)); |
michael@0 | 708 | #endif |
michael@0 | 709 | /* |
michael@0 | 710 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
michael@0 | 711 | is as in fopen ("rb" or "wb") but can also include a compression level |
michael@0 | 712 | ("wb9"). gzopen can be used to read a file which is not in gzip format; |
michael@0 | 713 | in this case gzread will directly read from the file without decompression. |
michael@0 | 714 | gzopen returns NULL if the file could not be opened or if there was |
michael@0 | 715 | insufficient memory to allocate the (de)compression state; errno |
michael@0 | 716 | can be checked to distinguish the two cases (if errno is zero, the |
michael@0 | 717 | zlib error is Z_MEM_ERROR). |
michael@0 | 718 | */ |
michael@0 | 719 | |
michael@0 | 720 | #ifdef MOZILLA_CLIENT |
michael@0 | 721 | PR_EXTERN(gzFile) gzdopen (int fd, const char *mode); |
michael@0 | 722 | #else |
michael@0 | 723 | extern gzFile EXPORT gzdopen OF((int fd, const char *mode)); |
michael@0 | 724 | #endif |
michael@0 | 725 | /* |
michael@0 | 726 | gzdopen() associates a gzFile with the file descriptor fd. File |
michael@0 | 727 | descriptors are obtained from calls like open, dup, creat, pipe or |
michael@0 | 728 | fileno (in the file has been previously opened with fopen). |
michael@0 | 729 | The mode parameter is as in gzopen. |
michael@0 | 730 | The next call of gzclose on the returned gzFile will also close the |
michael@0 | 731 | file descriptor fd, just like fclose(fdopen(fd), mode) closes the file |
michael@0 | 732 | descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). |
michael@0 | 733 | gzdopen returns NULL if there was insufficient memory to allocate |
michael@0 | 734 | the (de)compression state. |
michael@0 | 735 | */ |
michael@0 | 736 | |
michael@0 | 737 | #ifdef MOZILLA_CLIENT |
michael@0 | 738 | PR_EXTERN(int) gzread (gzFile file, voidp buf, unsigned len); |
michael@0 | 739 | #else |
michael@0 | 740 | extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len)); |
michael@0 | 741 | #endif |
michael@0 | 742 | /* |
michael@0 | 743 | Reads the given number of uncompressed bytes from the compressed file. |
michael@0 | 744 | If the input file was not in gzip format, gzread copies the given number |
michael@0 | 745 | of bytes into the buffer. |
michael@0 | 746 | gzread returns the number of uncompressed bytes actually read (0 for |
michael@0 | 747 | end of file, -1 for error). */ |
michael@0 | 748 | |
michael@0 | 749 | #ifdef MOZILLA_CLIENT |
michael@0 | 750 | PR_EXTERN(int) gzwrite (gzFile file, const voidp buf, unsigned len); |
michael@0 | 751 | #else |
michael@0 | 752 | extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len)); |
michael@0 | 753 | #endif |
michael@0 | 754 | /* |
michael@0 | 755 | Writes the given number of uncompressed bytes into the compressed file. |
michael@0 | 756 | gzwrite returns the number of uncompressed bytes actually written |
michael@0 | 757 | (0 in case of error). |
michael@0 | 758 | */ |
michael@0 | 759 | |
michael@0 | 760 | #ifdef MOZILLA_CLIENT |
michael@0 | 761 | PR_EXTERN(int) gzflush (gzFile file, int flush); |
michael@0 | 762 | #else |
michael@0 | 763 | extern int EXPORT gzflush OF((gzFile file, int flush)); |
michael@0 | 764 | #endif |
michael@0 | 765 | /* |
michael@0 | 766 | Flushes all pending output into the compressed file. The parameter |
michael@0 | 767 | flush is as in the deflate() function. The return value is the zlib |
michael@0 | 768 | error number (see function gzerror below). gzflush returns Z_OK if |
michael@0 | 769 | the flush parameter is Z_FINISH and all output could be flushed. |
michael@0 | 770 | gzflush should be called only when strictly necessary because it can |
michael@0 | 771 | degrade compression. |
michael@0 | 772 | */ |
michael@0 | 773 | |
michael@0 | 774 | #ifdef MOZILLA_CLIENT |
michael@0 | 775 | PR_EXTERN(int) gzclose (gzFile file); |
michael@0 | 776 | #else |
michael@0 | 777 | extern int EXPORT gzclose OF((gzFile file)); |
michael@0 | 778 | #endif |
michael@0 | 779 | /* |
michael@0 | 780 | Flushes all pending output if necessary, closes the compressed file |
michael@0 | 781 | and deallocates all the (de)compression state. The return value is the zlib |
michael@0 | 782 | error number (see function gzerror below). |
michael@0 | 783 | */ |
michael@0 | 784 | |
michael@0 | 785 | #ifdef MOZILLA_CLIENT |
michael@0 | 786 | PR_EXTERN(const char *) gzerror (gzFile file, int *errnum); |
michael@0 | 787 | #else |
michael@0 | 788 | extern const char * EXPORT gzerror OF((gzFile file, int *errnum)); |
michael@0 | 789 | #endif |
michael@0 | 790 | /* |
michael@0 | 791 | Returns the error message for the last error which occurred on the |
michael@0 | 792 | given compressed file. errnum is set to zlib error number. If an |
michael@0 | 793 | error occurred in the file system and not in the compression library, |
michael@0 | 794 | errnum is set to Z_ERRNO and the application may consult errno |
michael@0 | 795 | to get the exact error code. |
michael@0 | 796 | */ |
michael@0 | 797 | |
michael@0 | 798 | /* checksum functions */ |
michael@0 | 799 | |
michael@0 | 800 | /* |
michael@0 | 801 | These functions are not related to compression but are exported |
michael@0 | 802 | anyway because they might be useful in applications using the |
michael@0 | 803 | compression library. |
michael@0 | 804 | */ |
michael@0 | 805 | |
michael@0 | 806 | #ifdef MOZILLA_CLIENT |
michael@0 | 807 | PR_EXTERN(uLong) adler32 (uLong adler, const Bytef *buf, uInt len); |
michael@0 | 808 | #else |
michael@0 | 809 | extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); |
michael@0 | 810 | #endif |
michael@0 | 811 | |
michael@0 | 812 | /* |
michael@0 | 813 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
michael@0 | 814 | return the updated checksum. If buf is NULL, this function returns |
michael@0 | 815 | the required initial value for the checksum. |
michael@0 | 816 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed |
michael@0 | 817 | much faster. Usage example: |
michael@0 | 818 | |
michael@0 | 819 | uLong adler = adler32(0L, Z_NULL, 0); |
michael@0 | 820 | |
michael@0 | 821 | while (read_buffer(buffer, length) != EOF) { |
michael@0 | 822 | adler = adler32(adler, buffer, length); |
michael@0 | 823 | } |
michael@0 | 824 | if (adler != original_adler) error(); |
michael@0 | 825 | */ |
michael@0 | 826 | |
michael@0 | 827 | #ifdef MOZILLA_CLIENT |
michael@0 | 828 | PR_EXTERN(uLong) crc32 (uLong crc, const Bytef *buf, uInt len); |
michael@0 | 829 | #else |
michael@0 | 830 | extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); |
michael@0 | 831 | #endif |
michael@0 | 832 | /* |
michael@0 | 833 | Update a running crc with the bytes buf[0..len-1] and return the updated |
michael@0 | 834 | crc. If buf is NULL, this function returns the required initial value |
michael@0 | 835 | for the crc. Pre- and post-conditioning (one's complement) is performed |
michael@0 | 836 | within this function so it shouldn't be done by the application. |
michael@0 | 837 | Usage example: |
michael@0 | 838 | |
michael@0 | 839 | uLong crc = crc32(0L, Z_NULL, 0); |
michael@0 | 840 | |
michael@0 | 841 | while (read_buffer(buffer, length) != EOF) { |
michael@0 | 842 | crc = crc32(crc, buffer, length); |
michael@0 | 843 | } |
michael@0 | 844 | if (crc != original_crc) error(); |
michael@0 | 845 | */ |
michael@0 | 846 | |
michael@0 | 847 | |
michael@0 | 848 | /* various hacks, don't look :) */ |
michael@0 | 849 | |
michael@0 | 850 | /* deflateInit and inflateInit are macros to allow checking the zlib version |
michael@0 | 851 | * and the compiler's view of z_stream: |
michael@0 | 852 | */ |
michael@0 | 853 | #ifdef MOZILLA_CLIENT |
michael@0 | 854 | PR_EXTERN(int) deflateInit (z_streamp strm, int level, const char *version, |
michael@0 | 855 | int stream_size); |
michael@0 | 856 | PR_EXTERN(int) inflateInit_(z_streamp strm, const char *version, |
michael@0 | 857 | int stream_size); |
michael@0 | 858 | PR_EXTERN(int) deflateInit2_(z_streamp strm, int level, int method, |
michael@0 | 859 | int windowBits, int memLevel, int strategy, |
michael@0 | 860 | const char *version, int stream_size); |
michael@0 | 861 | PR_EXTERN(int) inflateInit2_(z_streamp strm, int windowBits, |
michael@0 | 862 | const char *version, int stream_size); |
michael@0 | 863 | #else |
michael@0 | 864 | extern int EXPORT deflateInit_ OF((z_streamp strm, int level, const char *version, |
michael@0 | 865 | int stream_size)); |
michael@0 | 866 | extern int EXPORT inflateInit_ OF((z_streamp strm, const char *version, |
michael@0 | 867 | int stream_size)); |
michael@0 | 868 | extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method, |
michael@0 | 869 | int windowBits, int memLevel, int strategy, |
michael@0 | 870 | const char *version, int stream_size)); |
michael@0 | 871 | extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits, |
michael@0 | 872 | const char *version, int stream_size)); |
michael@0 | 873 | #endif /* MOZILLA_CLIENT */ |
michael@0 | 874 | |
michael@0 | 875 | |
michael@0 | 876 | #define deflateInit(strm, level) \ |
michael@0 | 877 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) |
michael@0 | 878 | #define inflateInit(strm) \ |
michael@0 | 879 | inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) |
michael@0 | 880 | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ |
michael@0 | 881 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ |
michael@0 | 882 | (strategy), ZLIB_VERSION, sizeof(z_stream)) |
michael@0 | 883 | #define inflateInit2(strm, windowBits) \ |
michael@0 | 884 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) |
michael@0 | 885 | |
michael@0 | 886 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) |
michael@0 | 887 | struct internal_state {int dummy;}; /* hack for buggy compilers */ |
michael@0 | 888 | #endif |
michael@0 | 889 | |
michael@0 | 890 | uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */ |
michael@0 | 891 | |
michael@0 | 892 | #ifdef __cplusplus |
michael@0 | 893 | } |
michael@0 | 894 | #endif |
michael@0 | 895 | |
michael@0 | 896 | #endif /* _ZLIB_H */ |