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