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