Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenzlib.h
Go to the documentation of this file.
00001 /* zlib.h -- interface of the 'zlib' general purpose compression library 00002 version 1.1.4, March 11th, 2002 00003 00004 Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler 00005 00006 This software is provided 'as-is', without any express or implied 00007 warranty. In no event will the authors be held liable for any damages 00008 arising from the use of this software. 00009 00010 Permission is granted to anyone to use this software for any purpose, 00011 including commercial applications, and to alter it and redistribute it 00012 freely, subject to the following restrictions: 00013 00014 1. The origin of this software must not be misrepresented; you must not 00015 claim that you wrote the original software. If you use this software 00016 in a product, an acknowledgment in the product documentation would be 00017 appreciated but is not required. 00018 2. Altered source versions must be plainly marked as such, and must not be 00019 misrepresented as being the original software. 00020 3. This notice may not be removed or altered from any source distribution. 00021 00022 Jean-loup Gailly Mark Adler 00023 jloup@gzip.org madler@alumni.caltech.edu 00024 00025 00026 The data format used by the zlib library is described by RFCs (Request for 00027 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt 00028 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 00029 */ 00030 00031 #ifndef _ZLIB_H 00032 #define _ZLIB_H 00033 00034 #include "zconf.h" 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 #define ZLIB_VERSION "1.1.4" 00041 00042 /* 00043 The 'zlib' compression library provides in-memory compression and 00044 decompression functions, including integrity checks of the uncompressed 00045 data. This version of the library supports only one compression method 00046 (deflation) but other algorithms will be added later and will have the same 00047 stream interface. 00048 00049 Compression can be done in a single step if the buffers are large 00050 enough (for example if an input file is mmap'ed), or can be done by 00051 repeated calls of the compression function. In the latter case, the 00052 application must provide more input and/or consume the output 00053 (providing more output space) before each call. 00054 00055 The library also supports reading and writing files in gzip (.gz) format 00056 with an interface similar to that of stdio. 00057 00058 The library does not install any signal handler. The decoder checks 00059 the consistency of the compressed data, so the library should never 00060 crash even in case of corrupted input. 00061 */ 00062 00063 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 00064 typedef void (*free_func) OF((voidpf opaque, voidpf address)); 00065 00066 struct internal_state; 00067 00068 typedef struct z_stream_s { 00069 Bytef *next_in; /* next input byte */ 00070 uInt avail_in; /* number of bytes available at next_in */ 00071 uLong total_in; /* total nb of input bytes read so far */ 00072 00073 Bytef *next_out; /* next output byte should be put there */ 00074 uInt avail_out; /* remaining free space at next_out */ 00075 uLong total_out; /* total nb of bytes output so far */ 00076 00077 char *msg; /* last error message, NULL if no error */ 00078 struct internal_state FAR *state; /* not visible by applications */ 00079 00080 alloc_func zalloc; /* used to allocate the internal state */ 00081 free_func zfree; /* used to free the internal state */ 00082 voidpf opaque; /* private data object passed to zalloc and zfree */ 00083 00084 int data_type; /* best guess about the data type: ascii or binary */ 00085 uLong adler; /* adler32 value of the uncompressed data */ 00086 uLong reserved; /* reserved for future use */ 00087 } z_stream; 00088 00089 typedef z_stream FAR *z_streamp; 00090 00091 /* 00092 The application must update next_in and avail_in when avail_in has 00093 dropped to zero. It must update next_out and avail_out when avail_out 00094 has dropped to zero. The application must initialize zalloc, zfree and 00095 opaque before calling the init function. All other fields are set by the 00096 compression library and must not be updated by the application. 00097 00098 The opaque value provided by the application will be passed as the first 00099 parameter for calls of zalloc and zfree. This can be useful for custom 00100 memory management. The compression library attaches no meaning to the 00101 opaque value. 00102 00103 zalloc must return Z_NULL if there is not enough memory for the object. 00104 If zlib is used in a multi-threaded application, zalloc and zfree must be 00105 thread safe. 00106 00107 On 16-bit systems, the functions zalloc and zfree must be able to allocate 00108 exactly 65536 bytes, but will not be required to allocate more than this 00109 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 00110 pointers returned by zalloc for objects of exactly 65536 bytes *must* 00111 have their offset normalized to zero. The default allocation function 00112 provided by this library ensures this (see zutil.c). To reduce memory 00113 requirements and avoid any allocation of 64K objects, at the expense of 00114 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 00115 00116 The fields total_in and total_out can be used for statistics or 00117 progress reports. After compression, total_in holds the total size of 00118 the uncompressed data and may be saved for use in the decompressor 00119 (particularly if the decompressor wants to decompress everything in 00120 a single step). 00121 */ 00122 00123 /* constants */ 00124 00125 #define Z_NO_FLUSH 0 00126 #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 00127 #define Z_SYNC_FLUSH 2 00128 #define Z_FULL_FLUSH 3 00129 #define Z_FINISH 4 00130 /* Allowed flush values; see deflate() below for details */ 00131 00132 #define Z_OK 0 00133 #define Z_STREAM_END 1 00134 #define Z_NEED_DICT 2 00135 #define Z_ERRNO (-1) 00136 #define Z_STREAM_ERROR (-2) 00137 #define Z_DATA_ERROR (-3) 00138 #define Z_MEM_ERROR (-4) 00139 #define Z_BUF_ERROR (-5) 00140 #define Z_VERSION_ERROR (-6) 00141 /* Return codes for the compression/decompression functions. Negative 00142 * values are errors, positive values are used for special but normal events. 00143 */ 00144 00145 #define Z_NO_COMPRESSION 0 00146 #define Z_BEST_SPEED 1 00147 #define Z_BEST_COMPRESSION 9 00148 #define Z_DEFAULT_COMPRESSION (-1) 00149 /* compression levels */ 00150 00151 #define Z_FILTERED 1 00152 #define Z_HUFFMAN_ONLY 2 00153 #define Z_DEFAULT_STRATEGY 0 00154 /* compression strategy; see deflateInit2() below for details */ 00155 00156 #define Z_BINARY 0 00157 #define Z_ASCII 1 00158 #define Z_UNKNOWN 2 00159 /* Possible values of the data_type field */ 00160 00161 #define Z_DEFLATED 8 00162 /* The deflate compression method (the only one supported in this version) */ 00163 00164 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 00165 00166 00167 /* basic functions */ 00168 00169 /* The application can compare zlibVersion and ZLIB_VERSION for consistency. 00170 If the first character differs, the library code actually used is 00171 not compatible with the zlib.h header file used by the application. 00172 This check is automatically made by deflateInit and inflateInit. 00173 */ 00174 00175 /* 00176 ZEXTERN(int) deflateInit OF((z_streamp strm, int level)); 00177 00178 Initializes the internal stream state for compression. The fields 00179 zalloc, zfree and opaque must be initialized before by the caller. 00180 If zalloc and zfree are set to Z_NULL, deflateInit updates them to 00181 use default allocation functions. 00182 00183 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 00184 1 gives best speed, 9 gives best compression, 0 gives no compression at 00185 all (the input data is simply copied a block at a time). 00186 Z_DEFAULT_COMPRESSION requests a default compromise between speed and 00187 compression (currently equivalent to level 6). 00188 00189 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 00190 enough memory, Z_STREAM_ERROR if level is not a valid compression level, 00191 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 00192 with the version assumed by the caller (ZLIB_VERSION). 00193 msg is set to null if there is no error message. deflateInit does not 00194 perform any compression: this will be done by deflate(). 00195 */ 00196 00197 00198 /* 00199 deflate compresses as much data as possible, and stops when the input 00200 buffer becomes empty or the output buffer becomes full. It may introduce some 00201 output latency (reading input without producing any output) except when 00202 forced to flush. 00203 00204 The detailed semantics are as follows. deflate performs one or both of the 00205 following actions: 00206 00207 - Compress more input starting at next_in and update next_in and avail_in 00208 accordingly. If not all input can be processed (because there is not 00209 enough room in the output buffer), next_in and avail_in are updated and 00210 processing will resume at this point for the next call of deflate(). 00211 00212 - Provide more output starting at next_out and update next_out and avail_out 00213 accordingly. This action is forced if the parameter flush is non zero. 00214 Forcing flush frequently degrades the compression ratio, so this parameter 00215 should be set only when necessary (in interactive applications). 00216 Some output may be provided even if flush is not set. 00217 00218 Before the call of deflate(), the application should ensure that at least 00219 one of the actions is possible, by providing more input and/or consuming 00220 more output, and updating avail_in or avail_out accordingly; avail_out 00221 should never be zero before the call. The application can consume the 00222 compressed output when it wants, for example when the output buffer is full 00223 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 00224 and with zero avail_out, it must be called again after making room in the 00225 output buffer because there might be more output pending. 00226 00227 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 00228 flushed to the output buffer and the output is aligned on a byte boundary, so 00229 that the decompressor can get all input data available so far. (In particular 00230 avail_in is zero after the call if enough output space has been provided 00231 before the call.) Flushing may degrade compression for some compression 00232 algorithms and so it should be used only when necessary. 00233 00234 If flush is set to Z_FULL_FLUSH, all output is flushed as with 00235 Z_SYNC_FLUSH, and the compression state is reset so that decompression can 00236 restart from this point if previous compressed data has been damaged or if 00237 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 00238 the compression. 00239 00240 If deflate returns with avail_out == 0, this function must be called again 00241 with the same value of the flush parameter and more output space (updated 00242 avail_out), until the flush is complete (deflate returns with non-zero 00243 avail_out). 00244 00245 If the parameter flush is set to Z_FINISH, pending input is processed, 00246 pending output is flushed and deflate returns with Z_STREAM_END if there 00247 was enough output space; if deflate returns with Z_OK, this function must be 00248 called again with Z_FINISH and more output space (updated avail_out) but no 00249 more input data, until it returns with Z_STREAM_END or an error. After 00250 deflate has returned Z_STREAM_END, the only possible operations on the 00251 stream are deflateReset or deflateEnd. 00252 00253 Z_FINISH can be used immediately after deflateInit if all the compression 00254 is to be done in a single step. In this case, avail_out must be at least 00255 0.1% larger than avail_in plus 12 bytes. If deflate does not return 00256 Z_STREAM_END, then it must be called again as described above. 00257 00258 deflate() sets strm->adler to the adler32 checksum of all input read 00259 so far (that is, total_in bytes). 00260 00261 deflate() may update data_type if it can make a good guess about 00262 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered 00263 binary. This field is only for information purposes and does not affect 00264 the compression algorithm in any manner. 00265 00266 deflate() returns Z_OK if some progress has been made (more input 00267 processed or more output produced), Z_STREAM_END if all input has been 00268 consumed and all output has been produced (only when flush is set to 00269 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 00270 if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 00271 (for example avail_in or avail_out was zero). 00272 */ 00273 00274 00275 /* 00276 All dynamically allocated data structures for this stream are freed. 00277 This function discards any unprocessed input and does not flush any 00278 pending output. 00279 00280 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 00281 stream state was inconsistent, Z_DATA_ERROR if the stream was freed 00282 prematurely (some input or output was discarded). In the error case, 00283 msg may be set but then points to a static string (which must not be 00284 deallocated). 00285 */ 00286 00287 00288 /* 00289 ZEXTERN(int) inflateInit OF((z_streamp strm)); 00290 00291 Initializes the internal stream state for decompression. The fields 00292 next_in, avail_in, zalloc, zfree and opaque must be initialized before by 00293 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 00294 value depends on the compression method), inflateInit determines the 00295 compression method from the zlib header and allocates all data structures 00296 accordingly; otherwise the allocation will be deferred to the first call of 00297 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 00298 use default allocation functions. 00299 00300 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 00301 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 00302 version assumed by the caller. msg is set to null if there is no error 00303 message. inflateInit does not perform any decompression apart from reading 00304 the zlib header if present: this will be done by inflate(). (So next_in and 00305 avail_in may be modified, but next_out and avail_out are unchanged.) 00306 */ 00307 00308 00309 ZEXTERN(int) inflate OF((z_streamp strm, int flush)); 00310 /* 00311 inflate decompresses as much data as possible, and stops when the input 00312 buffer becomes empty or the output buffer becomes full. It may some 00313 introduce some output latency (reading input without producing any output) 00314 except when forced to flush. 00315 00316 The detailed semantics are as follows. inflate performs one or both of the 00317 following actions: 00318 00319 - Decompress more input starting at next_in and update next_in and avail_in 00320 accordingly. If not all input can be processed (because there is not 00321 enough room in the output buffer), next_in is updated and processing 00322 will resume at this point for the next call of inflate(). 00323 00324 - Provide more output starting at next_out and update next_out and avail_out 00325 accordingly. inflate() provides as much output as possible, until there 00326 is no more input data or no more space in the output buffer (see below 00327 about the flush parameter). 00328 00329 Before the call of inflate(), the application should ensure that at least 00330 one of the actions is possible, by providing more input and/or consuming 00331 more output, and updating the next_* and avail_* values accordingly. 00332 The application can consume the uncompressed output when it wants, for 00333 example when the output buffer is full (avail_out == 0), or after each 00334 call of inflate(). If inflate returns Z_OK and with zero avail_out, it 00335 must be called again after making room in the output buffer because there 00336 might be more output pending. 00337 00338 If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much 00339 output as possible to the output buffer. The flushing behavior of inflate is 00340 not specified for values of the flush parameter other than Z_SYNC_FLUSH 00341 and Z_FINISH, but the current implementation actually flushes as much output 00342 as possible anyway. 00343 00344 inflate() should normally be called until it returns Z_STREAM_END or an 00345 error. However if all decompression is to be performed in a single step 00346 (a single call of inflate), the parameter flush should be set to 00347 Z_FINISH. In this case all pending input is processed and all pending 00348 output is flushed; avail_out must be large enough to hold all the 00349 uncompressed data. (The size of the uncompressed data may have been saved 00350 by the compressor for this purpose.) The next operation on this stream must 00351 be inflateEnd to deallocate the decompression state. The use of Z_FINISH 00352 is never required, but can be used to inform inflate that a faster routine 00353 may be used for the single inflate() call. 00354 00355 If a preset dictionary is needed at this point (see inflateSetDictionary 00356 below), inflate sets strm-adler to the adler32 checksum of the 00357 dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise 00358 it sets strm->adler to the adler32 checksum of all output produced 00359 so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or 00360 an error code as described below. At the end of the stream, inflate() 00361 checks that its computed adler32 checksum is equal to that saved by the 00362 compressor and returns Z_STREAM_END only if the checksum is correct. 00363 00364 inflate() returns Z_OK if some progress has been made (more input processed 00365 or more output produced), Z_STREAM_END if the end of the compressed data has 00366 been reached and all uncompressed output has been produced, Z_NEED_DICT if a 00367 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 00368 corrupted (input stream not conforming to the zlib format or incorrect 00369 adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent 00370 (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not 00371 enough memory, Z_BUF_ERROR if no progress is possible or if there was not 00372 enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR 00373 case, the application may then call inflateSync to look for a good 00374 compression block. 00375 */ 00376 00377 00378 ZEXTERN(int) inflateEnd OF((z_streamp strm)); 00379 /* 00380 All dynamically allocated data structures for this stream are freed. 00381 This function discards any unprocessed input and does not flush any 00382 pending output. 00383 00384 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 00385 was inconsistent. In the error case, msg may be set but then points to a 00386 static string (which must not be deallocated). 00387 */ 00388 00389 /* Advanced functions */ 00390 00391 /* 00392 The following functions are needed only in some special applications. 00393 */ 00394 00395 /* 00396 ZEXTERN(int) deflateInit2 OF((z_streamp strm, 00397 int level, 00398 int method, 00399 int windowBits, 00400 int memLevel, 00401 int strategy)); 00402 00403 This is another version of deflateInit with more compression options. The 00404 fields next_in, zalloc, zfree and opaque must be initialized before by 00405 the caller. 00406 00407 The method parameter is the compression method. It must be Z_DEFLATED in 00408 this version of the library. 00409 00410 The windowBits parameter is the base two logarithm of the window size 00411 (the size of the history buffer). It should be in the range 8..15 for this 00412 version of the library. Larger values of this parameter result in better 00413 compression at the expense of memory usage. The default value is 15 if 00414 deflateInit is used instead. 00415 00416 The memLevel parameter specifies how much memory should be allocated 00417 for the internal compression state. memLevel=1 uses minimum memory but 00418 is slow and reduces compression ratio; memLevel=9 uses maximum memory 00419 for optimal speed. The default value is 8. See zconf.h for total memory 00420 usage as a function of windowBits and memLevel. 00421 00422 The strategy parameter is used to tune the compression algorithm. Use the 00423 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 00424 filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no 00425 string match). Filtered data consists mostly of small values with a 00426 somewhat random distribution. In this case, the compression algorithm is 00427 tuned to compress them better. The effect of Z_FILTERED is to force more 00428 Huffman coding and less string matching; it is somewhat intermediate 00429 between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects 00430 the compression ratio but not the correctness of the compressed output even 00431 if it is not set appropriately. 00432 00433 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 00434 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 00435 method). msg is set to null if there is no error message. deflateInit2 does 00436 not perform any compression: this will be done by deflate(). 00437 */ 00438 00439 /* 00440 Initializes the compression dictionary from the given byte sequence 00441 without producing any compressed output. This function must be called 00442 immediately after deflateInit, deflateInit2 or deflateReset, before any 00443 call of deflate. The compressor and decompressor must use exactly the same 00444 dictionary (see inflateSetDictionary). 00445 00446 The dictionary should consist of strings (byte sequences) that are likely 00447 to be encountered later in the data to be compressed, with the most commonly 00448 used strings preferably put towards the end of the dictionary. Using a 00449 dictionary is most useful when the data to be compressed is short and can be 00450 predicted with good accuracy; the data can then be compressed better than 00451 with the default empty dictionary. 00452 00453 Depending on the size of the compression data structures selected by 00454 deflateInit or deflateInit2, a part of the dictionary may in effect be 00455 discarded, for example if the dictionary is larger than the window size in 00456 deflate or deflate2. Thus the strings most likely to be useful should be 00457 put at the end of the dictionary, not at the front. 00458 00459 Upon return of this function, strm->adler is set to the Adler32 value 00460 of the dictionary; the decompressor may later use this value to determine 00461 which dictionary has been used by the compressor. (The Adler32 value 00462 applies to the whole dictionary even if only a subset of the dictionary is 00463 actually used by the compressor.) 00464 00465 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 00466 parameter is invalid (such as NULL dictionary) or the stream state is 00467 inconsistent (for example if deflate has already been called for this stream 00468 or if the compression method is bsort). deflateSetDictionary does not 00469 perform any compression: this will be done by deflate(). 00470 */ 00471 00472 /* 00473 Sets the destination stream as a complete copy of the source stream. 00474 00475 This function can be useful when several compression strategies will be 00476 tried, for example when there are several ways of pre-processing the input 00477 data with a filter. The streams that will be discarded should then be freed 00478 by calling deflateEnd. Note that deflateCopy duplicates the internal 00479 compression state which can be quite large, so this strategy is slow and 00480 can consume lots of memory. 00481 00482 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 00483 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 00484 (such as zalloc being NULL). msg is left unchanged in both source and 00485 destination. 00486 */ 00487 00488 /* 00489 This function is equivalent to deflateEnd followed by deflateInit, 00490 but does not free and reallocate all the internal compression state. 00491 The stream will keep the same compression level and any other attributes 00492 that may have been set by deflateInit2. 00493 00494 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 00495 stream state was inconsistent (such as zalloc or state being NULL). 00496 */ 00497 00498 /* 00499 Dynamically update the compression level and compression strategy. The 00500 interpretation of level and strategy is as in deflateInit2. This can be 00501 used to switch between compression and straight copy of the input data, or 00502 to switch to a different kind of input data requiring a different 00503 strategy. If the compression level is changed, the input available so far 00504 is compressed with the old level (and may be flushed); the new level will 00505 take effect only at the next call of deflate(). 00506 00507 Before the call of deflateParams, the stream state must be set as for 00508 a call of deflate(), since the currently available input may have to 00509 be compressed and flushed. In particular, strm->avail_out must be non-zero. 00510 00511 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 00512 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 00513 if strm->avail_out was zero. 00514 */ 00515 00516 /* 00517 ZEXTERN(int) inflateInit2 OF((z_streamp strm, 00518 int windowBits)); 00519 00520 This is another version of inflateInit with an extra parameter. The 00521 fields next_in, avail_in, zalloc, zfree and opaque must be initialized 00522 before by the caller. 00523 00524 The windowBits parameter is the base two logarithm of the maximum window 00525 size (the size of the history buffer). It should be in the range 8..15 for 00526 this version of the library. The default value is 15 if inflateInit is used 00527 instead. If a compressed stream with a larger window size is given as 00528 input, inflate() will return with the error code Z_DATA_ERROR instead of 00529 trying to allocate a larger window. 00530 00531 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 00532 memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative 00533 memLevel). msg is set to null if there is no error message. inflateInit2 00534 does not perform any decompression apart from reading the zlib header if 00535 present: this will be done by inflate(). (So next_in and avail_in may be 00536 modified, but next_out and avail_out are unchanged.) 00537 */ 00538 00539 /* 00540 Initializes the decompression dictionary from the given uncompressed byte 00541 sequence. This function must be called immediately after a call of inflate 00542 if this call returned Z_NEED_DICT. The dictionary chosen by the compressor 00543 can be determined from the Adler32 value returned by this call of 00544 inflate. The compressor and decompressor must use exactly the same 00545 dictionary (see deflateSetDictionary). 00546 00547 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 00548 parameter is invalid (such as NULL dictionary) or the stream state is 00549 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 00550 expected one (incorrect Adler32 value). inflateSetDictionary does not 00551 perform any decompression: this will be done by subsequent calls of 00552 inflate(). 00553 */ 00554 00555 /* 00556 Skips invalid compressed data until a full flush point (see above the 00557 description of deflate with Z_FULL_FLUSH) can be found, or until all 00558 available input is skipped. No output is provided. 00559 00560 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 00561 if no more input was provided, Z_DATA_ERROR if no flush point has been found, 00562 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 00563 case, the application may save the current current value of total_in which 00564 indicates where valid compressed data was found. In the error case, the 00565 application may repeatedly call inflateSync, providing more input each time, 00566 until success or end of the input data. 00567 */ 00568 00569 ZEXTERN(int) inflateReset OF((z_streamp strm)); 00570 /* 00571 This function is equivalent to inflateEnd followed by inflateInit, 00572 but does not free and reallocate all the internal decompression state. 00573 The stream will keep attributes that may have been set by inflateInit2. 00574 00575 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 00576 stream state was inconsistent (such as zalloc or state being NULL). 00577 */ 00578 00579 00580 /* utility functions */ 00581 00582 /* 00583 The following utility functions are implemented on top of the 00584 basic stream-oriented functions. To simplify the interface, some 00585 default options are assumed (compression level and memory usage, 00586 standard memory allocation functions). The source code of these 00587 utility functions can easily be modified if you need special options. 00588 */ 00589 00590 /* 00591 Compresses the source buffer into the destination buffer. sourceLen is 00592 the byte length of the source buffer. Upon entry, destLen is the total 00593 size of the destination buffer, which must be at least 0.1% larger than 00594 sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the 00595 compressed buffer. 00596 This function can be used to compress a whole file at once if the 00597 input file is mmap'ed. 00598 compress returns Z_OK if success, Z_MEM_ERROR if there was not 00599 enough memory, Z_BUF_ERROR if there was not enough room in the output 00600 buffer. 00601 */ 00602 00603 /* 00604 Compresses the source buffer into the destination buffer. The level 00605 parameter has the same meaning as in deflateInit. sourceLen is the byte 00606 length of the source buffer. Upon entry, destLen is the total size of the 00607 destination buffer, which must be at least 0.1% larger than sourceLen plus 00608 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 00609 00610 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 00611 memory, Z_BUF_ERROR if there was not enough room in the output buffer, 00612 Z_STREAM_ERROR if the level parameter is invalid. 00613 */ 00614 00615 /* 00616 Decompresses the source buffer into the destination buffer. sourceLen is 00617 the byte length of the source buffer. Upon entry, destLen is the total 00618 size of the destination buffer, which must be large enough to hold the 00619 entire uncompressed data. (The size of the uncompressed data must have 00620 been saved previously by the compressor and transmitted to the decompressor 00621 by some mechanism outside the scope of this compression library.) 00622 Upon exit, destLen is the actual size of the compressed buffer. 00623 This function can be used to decompress a whole file at once if the 00624 input file is mmap'ed. 00625 00626 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 00627 enough memory, Z_BUF_ERROR if there was not enough room in the output 00628 buffer, or Z_DATA_ERROR if the input data was corrupted. 00629 */ 00630 00631 00632 /* 00633 Opens a gzip (.gz) file for reading or writing. The mode parameter 00634 is as in fopen ("rb" or "wb") but can also include a compression level 00635 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 00636 Huffman only compression as in "wb1h". (See the description 00637 of deflateInit2 for more information about the strategy parameter.) 00638 00639 gzopen can be used to read a file which is not in gzip format; in this 00640 case gzread will directly read from the file without decompression. 00641 00642 gzopen returns NULL if the file could not be opened or if there was 00643 insufficient memory to allocate the (de)compression state; errno 00644 can be checked to distinguish the two cases (if errno is zero, the 00645 zlib error is Z_MEM_ERROR). */ 00646 00647 /* 00648 gzdopen() associates a gzFile with the file descriptor fd. File 00649 descriptors are obtained from calls like open, dup, creat, pipe or 00650 fileno (in the file has been previously opened with fopen). 00651 The mode parameter is as in gzopen. 00652 The next call of gzclose on the returned gzFile will also close the 00653 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 00654 descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 00655 gzdopen returns NULL if there was insufficient memory to allocate 00656 the (de)compression state. 00657 */ 00658 00659 /* 00660 Dynamically update the compression level or strategy. See the description 00661 of deflateInit2 for the meaning of these parameters. 00662 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 00663 opened for writing. 00664 */ 00665 00666 /* 00667 Reads the given number of uncompressed bytes from the compressed file. 00668 If the input file was not in gzip format, gzread copies the given number 00669 of bytes into the buffer. 00670 gzread returns the number of uncompressed bytes actually read (0 for 00671 end of file, -1 for error). */ 00672 00673 /* 00674 Writes the given number of uncompressed bytes into the compressed file. 00675 gzwrite returns the number of uncompressed bytes actually written 00676 (0 in case of error). 00677 */ 00678 00679 /* 00680 Converts, formats, and writes the args to the compressed file under 00681 control of the format string, as in fprintf. gzprintf returns the number of 00682 uncompressed bytes actually written (0 in case of error). 00683 */ 00684 00685 /* 00686 Writes the given null-terminated string to the compressed file, excluding 00687 the terminating null character. 00688 gzputs returns the number of characters written, or -1 in case of error. 00689 */ 00690 00691 /* 00692 Reads bytes from the compressed file until len-1 characters are read, or 00693 a newline character is read and transferred to buf, or an end-of-file 00694 condition is encountered. The string is then terminated with a null 00695 character. 00696 gzgets returns buf, or Z_NULL in case of error. 00697 */ 00698 00699 /* 00700 Writes c, converted to an unsigned char, into the compressed file. 00701 gzputc returns the value that was written, or -1 in case of error. 00702 */ 00703 00704 /* 00705 Reads one byte from the compressed file. gzgetc returns this byte 00706 or -1 in case of end of file or error. 00707 */ 00708 00709 /* 00710 Flushes all pending output into the compressed file. The parameter 00711 flush is as in the deflate() function. The return value is the zlib 00712 error number (see function gzerror below). gzflush returns Z_OK if 00713 the flush parameter is Z_FINISH and all output could be flushed. 00714 gzflush should be called only when strictly necessary because it can 00715 degrade compression. 00716 */ 00717 00718 /* 00719 Sets the starting position for the next gzread or gzwrite on the 00720 given compressed file. The offset represents a number of bytes in the 00721 uncompressed data stream. The whence parameter is defined as in lseek(2); 00722 the value SEEK_END is not supported. 00723 If the file is opened for reading, this function is emulated but can be 00724 extremely slow. If the file is opened for writing, only forward seeks are 00725 supported; gzseek then compresses a sequence of zeroes up to the new 00726 starting position. 00727 00728 gzseek returns the resulting offset location as measured in bytes from 00729 the beginning of the uncompressed stream, or -1 in case of error, in 00730 particular if the file is opened for writing and the new starting position 00731 would be before the current position. 00732 */ 00733 00734 /* 00735 Rewinds the given file. This function is supported only for reading. 00736 00737 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 00738 */ 00739 00740 /* 00741 Returns the starting position for the next gzread or gzwrite on the 00742 given compressed file. This position represents a number of bytes in the 00743 uncompressed data stream. 00744 00745 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 00746 */ 00747 00748 /* 00749 Returns 1 when EOF has previously been detected reading the given 00750 input stream, otherwise zero. 00751 */ 00752 00753 /* 00754 Flushes all pending output if necessary, closes the compressed file 00755 and deallocates all the (de)compression state. The return value is the zlib 00756 error number (see function gzerror below). 00757 */ 00758 00759 /* 00760 Returns the error message for the last error which occurred on the 00761 given compressed file. errnum is set to zlib error number. If an 00762 error occurred in the file system and not in the compression library, 00763 errnum is set to Z_ERRNO and the application may consult errno 00764 to get the exact error code. 00765 */ 00766 00767 /* checksum functions */ 00768 00769 /* 00770 These functions are not related to compression but are exported 00771 anyway because they might be useful in applications using the 00772 compression library. 00773 */ 00774 00775 ZEXTERN(uLong) adler32 OF((uLong adler, const Bytef *buf, uInt len)); 00776 00777 /* 00778 Update a running Adler-32 checksum with the bytes buf[0..len-1] and 00779 return the updated checksum. If buf is NULL, this function returns 00780 the required initial value for the checksum. 00781 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 00782 much faster. Usage example: 00783 00784 uLong adler = adler32(0L, Z_NULL, 0); 00785 00786 while (read_buffer(buffer, length) != EOF) { 00787 adler = adler32(adler, buffer, length); 00788 } 00789 if (adler != original_adler) error(); 00790 */ 00791 00792 /* 00793 Update a running crc with the bytes buf[0..len-1] and return the updated 00794 crc. If buf is NULL, this function returns the required initial value 00795 for the crc. Pre- and post-conditioning (one's complement) is performed 00796 within this function so it shouldn't be done by the application. 00797 Usage example: 00798 00799 uLong crc = crc32(0L, Z_NULL, 0); 00800 00801 while (read_buffer(buffer, length) != EOF) { 00802 crc = crc32(crc, buffer, length); 00803 } 00804 if (crc != original_crc) error(); 00805 */ 00806 00807 00808 /* various hacks, don't look :) */ 00809 00810 /* deflateInit and inflateInit are macros to allow checking the zlib version 00811 * and the compiler's view of z_stream: 00812 */ 00813 ZEXTERN(int) inflateInit2_ OF((z_streamp strm, int windowBits, 00814 const char *version, int stream_size)); 00815 #define deflateInit(strm, level) \ 00816 deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 00817 #define inflateInit(strm) \ 00818 inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 00819 #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 00820 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 00821 (strategy), ZLIB_VERSION, sizeof(z_stream)) 00822 #define inflateInit2(strm, windowBits) \ 00823 inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 00824 00825 00826 #ifdef __cplusplus 00827 } 00828 #endif 00829 00830 #endif /* _ZLIB_H */ Generated on Sat May 26 2012 04:32:06 for ReactOS by
1.7.6.1
|