zlib.h revision 1.1 1 1.1 paulus /* $NetBSD: zlib.h,v 1.1 1996/03/15 02:28:17 paulus Exp $ */
2 1.1 paulus
3 1.1 paulus /*
4 1.1 paulus * This file is derived from zlib.h and zconf.h from the zlib-0.95
5 1.1 paulus * distribution by Jean-loup Gailly and Mark Adler, with some additions
6 1.1 paulus * by Paul Mackerras to aid in implementing Deflate compression and
7 1.1 paulus * decompression for PPP packets.
8 1.1 paulus */
9 1.1 paulus
10 1.1 paulus /* zlib.h -- interface of the 'zlib' general purpose compression library
11 1.1 paulus version 0.95, Aug 16th, 1995.
12 1.1 paulus
13 1.1 paulus Copyright (C) 1995 Jean-loup Gailly and Mark Adler
14 1.1 paulus
15 1.1 paulus This software is provided 'as-is', without any express or implied
16 1.1 paulus warranty. In no event will the authors be held liable for any damages
17 1.1 paulus arising from the use of this software.
18 1.1 paulus
19 1.1 paulus Permission is granted to anyone to use this software for any purpose,
20 1.1 paulus including commercial applications, and to alter it and redistribute it
21 1.1 paulus freely, subject to the following restrictions:
22 1.1 paulus
23 1.1 paulus 1. The origin of this software must not be misrepresented; you must not
24 1.1 paulus claim that you wrote the original software. If you use this software
25 1.1 paulus in a product, an acknowledgment in the product documentation would be
26 1.1 paulus appreciated but is not required.
27 1.1 paulus 2. Altered source versions must be plainly marked as such, and must not be
28 1.1 paulus misrepresented as being the original software.
29 1.1 paulus 3. This notice may not be removed or altered from any source distribution.
30 1.1 paulus
31 1.1 paulus Jean-loup Gailly Mark Adler
32 1.1 paulus gzip (at) prep.ai.mit.edu madler (at) alumni.caltech.edu
33 1.1 paulus */
34 1.1 paulus
35 1.1 paulus #ifndef _ZLIB_H
36 1.1 paulus #define _ZLIB_H
37 1.1 paulus
38 1.1 paulus /* #include "zconf.h" */ /* included directly here */
39 1.1 paulus
40 1.1 paulus /* zconf.h -- configuration of the zlib compression library
41 1.1 paulus * Copyright (C) 1995 Jean-loup Gailly.
42 1.1 paulus * For conditions of distribution and use, see copyright notice in zlib.h
43 1.1 paulus */
44 1.1 paulus
45 1.1 paulus /* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
46 1.1 paulus
47 1.1 paulus /*
48 1.1 paulus The library does not install any signal handler. It is recommended to
49 1.1 paulus add at least a handler for SIGSEGV when decompressing; the library checks
50 1.1 paulus the consistency of the input data whenever possible but may go nuts
51 1.1 paulus for some forms of corrupted input.
52 1.1 paulus */
53 1.1 paulus
54 1.1 paulus /*
55 1.1 paulus * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
56 1.1 paulus * than 64k bytes at a time (needed on systems with 16-bit int).
57 1.1 paulus * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
58 1.1 paulus * at addresses which are not a multiple of their size.
59 1.1 paulus * Under DOS, -DFAR=far or -DFAR=__far may be needed.
60 1.1 paulus */
61 1.1 paulus
62 1.1 paulus #ifndef STDC
63 1.1 paulus # if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
64 1.1 paulus # define STDC
65 1.1 paulus # endif
66 1.1 paulus #endif
67 1.1 paulus
68 1.1 paulus #ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
69 1.1 paulus # include <unix.h>
70 1.1 paulus #endif
71 1.1 paulus
72 1.1 paulus /* Maximum value for memLevel in deflateInit2 */
73 1.1 paulus #ifndef MAX_MEM_LEVEL
74 1.1 paulus # ifdef MAXSEG_64K
75 1.1 paulus # define MAX_MEM_LEVEL 8
76 1.1 paulus # else
77 1.1 paulus # define MAX_MEM_LEVEL 9
78 1.1 paulus # endif
79 1.1 paulus #endif
80 1.1 paulus
81 1.1 paulus #ifndef FAR
82 1.1 paulus # define FAR
83 1.1 paulus #endif
84 1.1 paulus
85 1.1 paulus /* Maximum value for windowBits in deflateInit2 and inflateInit2 */
86 1.1 paulus #ifndef MAX_WBITS
87 1.1 paulus # define MAX_WBITS 15 /* 32K LZ77 window */
88 1.1 paulus #endif
89 1.1 paulus
90 1.1 paulus /* The memory requirements for deflate are (in bytes):
91 1.1 paulus 1 << (windowBits+2) + 1 << (memLevel+9)
92 1.1 paulus that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
93 1.1 paulus plus a few kilobytes for small objects. For example, if you want to reduce
94 1.1 paulus the default memory requirements from 256K to 128K, compile with
95 1.1 paulus make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
96 1.1 paulus Of course this will generally degrade compression (there's no free lunch).
97 1.1 paulus
98 1.1 paulus The memory requirements for inflate are (in bytes) 1 << windowBits
99 1.1 paulus that is, 32K for windowBits=15 (default value) plus a few kilobytes
100 1.1 paulus for small objects.
101 1.1 paulus */
102 1.1 paulus
103 1.1 paulus /* Type declarations */
104 1.1 paulus
105 1.1 paulus #ifndef OF /* function prototypes */
106 1.1 paulus # ifdef STDC
107 1.1 paulus # define OF(args) args
108 1.1 paulus # else
109 1.1 paulus # define OF(args) ()
110 1.1 paulus # endif
111 1.1 paulus #endif
112 1.1 paulus
113 1.1 paulus typedef unsigned char Byte; /* 8 bits */
114 1.1 paulus typedef unsigned int uInt; /* 16 bits or more */
115 1.1 paulus typedef unsigned long uLong; /* 32 bits or more */
116 1.1 paulus
117 1.1 paulus typedef Byte FAR Bytef;
118 1.1 paulus typedef char FAR charf;
119 1.1 paulus typedef int FAR intf;
120 1.1 paulus typedef uInt FAR uIntf;
121 1.1 paulus typedef uLong FAR uLongf;
122 1.1 paulus
123 1.1 paulus #ifdef STDC
124 1.1 paulus typedef void FAR *voidpf;
125 1.1 paulus typedef void *voidp;
126 1.1 paulus #else
127 1.1 paulus typedef Byte FAR *voidpf;
128 1.1 paulus typedef Byte *voidp;
129 1.1 paulus #endif
130 1.1 paulus
131 1.1 paulus /* end of original zconf.h */
132 1.1 paulus
133 1.1 paulus #define ZLIB_VERSION "0.95P"
134 1.1 paulus
135 1.1 paulus /*
136 1.1 paulus The 'zlib' compression library provides in-memory compression and
137 1.1 paulus decompression functions, including integrity checks of the uncompressed
138 1.1 paulus data. This version of the library supports only one compression method
139 1.1 paulus (deflation) but other algorithms may be added later and will have the same
140 1.1 paulus stream interface.
141 1.1 paulus
142 1.1 paulus For compression the application must provide the output buffer and
143 1.1 paulus may optionally provide the input buffer for optimization. For decompression,
144 1.1 paulus the application must provide the input buffer and may optionally provide
145 1.1 paulus the output buffer for optimization.
146 1.1 paulus
147 1.1 paulus Compression can be done in a single step if the buffers are large
148 1.1 paulus enough (for example if an input file is mmap'ed), or can be done by
149 1.1 paulus repeated calls of the compression function. In the latter case, the
150 1.1 paulus application must provide more input and/or consume the output
151 1.1 paulus (providing more output space) before each call.
152 1.1 paulus */
153 1.1 paulus
154 1.1 paulus typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
155 1.1 paulus typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt nbytes));
156 1.1 paulus
157 1.1 paulus struct internal_state;
158 1.1 paulus
159 1.1 paulus typedef struct z_stream_s {
160 1.1 paulus Bytef *next_in; /* next input byte */
161 1.1 paulus uInt avail_in; /* number of bytes available at next_in */
162 1.1 paulus uLong total_in; /* total nb of input bytes read so far */
163 1.1 paulus
164 1.1 paulus Bytef *next_out; /* next output byte should be put there */
165 1.1 paulus uInt avail_out; /* remaining free space at next_out */
166 1.1 paulus uLong total_out; /* total nb of bytes output so far */
167 1.1 paulus
168 1.1 paulus char *msg; /* last error message, NULL if no error */
169 1.1 paulus struct internal_state FAR *state; /* not visible by applications */
170 1.1 paulus
171 1.1 paulus alloc_func zalloc; /* used to allocate the internal state */
172 1.1 paulus free_func zfree; /* used to free the internal state */
173 1.1 paulus voidp opaque; /* private data object passed to zalloc and zfree */
174 1.1 paulus
175 1.1 paulus Byte data_type; /* best guess about the data type: ascii or binary */
176 1.1 paulus
177 1.1 paulus } z_stream;
178 1.1 paulus
179 1.1 paulus /*
180 1.1 paulus The application must update next_in and avail_in when avail_in has
181 1.1 paulus dropped to zero. It must update next_out and avail_out when avail_out
182 1.1 paulus has dropped to zero. The application must initialize zalloc, zfree and
183 1.1 paulus opaque before calling the init function. All other fields are set by the
184 1.1 paulus compression library and must not be updated by the application.
185 1.1 paulus
186 1.1 paulus The opaque value provided by the application will be passed as the first
187 1.1 paulus parameter for calls of zalloc and zfree. This can be useful for custom
188 1.1 paulus memory management. The compression library attaches no meaning to the
189 1.1 paulus opaque value.
190 1.1 paulus
191 1.1 paulus zalloc must return Z_NULL if there is not enough memory for the object.
192 1.1 paulus On 16-bit systems, the functions zalloc and zfree must be able to allocate
193 1.1 paulus exactly 65536 bytes, but will not be required to allocate more than this
194 1.1 paulus if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
195 1.1 paulus pointers returned by zalloc for objects of exactly 65536 bytes *must*
196 1.1 paulus have their offset normalized to zero. The default allocation function
197 1.1 paulus provided by this library ensures this (see zutil.c). To reduce memory
198 1.1 paulus requirements and avoid any allocation of 64K objects, at the expense of
199 1.1 paulus compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
200 1.1 paulus
201 1.1 paulus The fields total_in and total_out can be used for statistics or
202 1.1 paulus progress reports. After compression, total_in holds the total size of
203 1.1 paulus the uncompressed data and may be saved for use in the decompressor
204 1.1 paulus (particularly if the decompressor wants to decompress everything in
205 1.1 paulus a single step).
206 1.1 paulus */
207 1.1 paulus
208 1.1 paulus /* constants */
209 1.1 paulus
210 1.1 paulus #define Z_NO_FLUSH 0
211 1.1 paulus #define Z_PARTIAL_FLUSH 1
212 1.1 paulus #define Z_FULL_FLUSH 2
213 1.1 paulus #define Z_SYNC_FLUSH 3 /* experimental: partial_flush + byte align */
214 1.1 paulus #define Z_FINISH 4
215 1.1 paulus #define Z_PACKET_FLUSH 5
216 1.1 paulus /* See deflate() below for the usage of these constants */
217 1.1 paulus
218 1.1 paulus #define Z_OK 0
219 1.1 paulus #define Z_STREAM_END 1
220 1.1 paulus #define Z_ERRNO (-1)
221 1.1 paulus #define Z_STREAM_ERROR (-2)
222 1.1 paulus #define Z_DATA_ERROR (-3)
223 1.1 paulus #define Z_MEM_ERROR (-4)
224 1.1 paulus #define Z_BUF_ERROR (-5)
225 1.1 paulus /* error codes for the compression/decompression functions */
226 1.1 paulus
227 1.1 paulus #define Z_BEST_SPEED 1
228 1.1 paulus #define Z_BEST_COMPRESSION 9
229 1.1 paulus #define Z_DEFAULT_COMPRESSION (-1)
230 1.1 paulus /* compression levels */
231 1.1 paulus
232 1.1 paulus #define Z_FILTERED 1
233 1.1 paulus #define Z_HUFFMAN_ONLY 2
234 1.1 paulus #define Z_DEFAULT_STRATEGY 0
235 1.1 paulus
236 1.1 paulus #define Z_BINARY 0
237 1.1 paulus #define Z_ASCII 1
238 1.1 paulus #define Z_UNKNOWN 2
239 1.1 paulus /* Used to set the data_type field */
240 1.1 paulus
241 1.1 paulus #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
242 1.1 paulus
243 1.1 paulus extern char *zlib_version;
244 1.1 paulus /* The application can compare zlib_version and ZLIB_VERSION for consistency.
245 1.1 paulus If the first character differs, the library code actually used is
246 1.1 paulus not compatible with the zlib.h header file used by the application.
247 1.1 paulus */
248 1.1 paulus
249 1.1 paulus /* basic functions */
250 1.1 paulus
251 1.1 paulus extern int deflateInit OF((z_stream *strm, int level));
252 1.1 paulus /*
253 1.1 paulus Initializes the internal stream state for compression. The fields
254 1.1 paulus zalloc, zfree and opaque must be initialized before by the caller.
255 1.1 paulus If zalloc and zfree are set to Z_NULL, deflateInit updates them to
256 1.1 paulus use default allocation functions.
257 1.1 paulus
258 1.1 paulus The compression level must be Z_DEFAULT_COMPRESSION, or between 1 and 9:
259 1.1 paulus 1 gives best speed, 9 gives best compression. Z_DEFAULT_COMPRESSION requests
260 1.1 paulus a default compromise between speed and compression (currently equivalent
261 1.1 paulus to level 6).
262 1.1 paulus
263 1.1 paulus deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
264 1.1 paulus enough memory, Z_STREAM_ERROR if level is not a valid compression level.
265 1.1 paulus msg is set to null if there is no error message. deflateInit does not
266 1.1 paulus perform any compression: this will be done by deflate().
267 1.1 paulus */
268 1.1 paulus
269 1.1 paulus
270 1.1 paulus extern int deflate OF((z_stream *strm, int flush));
271 1.1 paulus /*
272 1.1 paulus Performs one or both of the following actions:
273 1.1 paulus
274 1.1 paulus - Compress more input starting at next_in and update next_in and avail_in
275 1.1 paulus accordingly. If not all input can be processed (because there is not
276 1.1 paulus enough room in the output buffer), next_in and avail_in are updated and
277 1.1 paulus processing will resume at this point for the next call of deflate().
278 1.1 paulus
279 1.1 paulus - Provide more output starting at next_out and update next_out and avail_out
280 1.1 paulus accordingly. This action is forced if the parameter flush is non zero.
281 1.1 paulus Forcing flush frequently degrades the compression ratio, so this parameter
282 1.1 paulus should be set only when necessary (in interactive applications).
283 1.1 paulus Some output may be provided even if flush is not set.
284 1.1 paulus
285 1.1 paulus Before the call of deflate(), the application should ensure that at least
286 1.1 paulus one of the actions is possible, by providing more input and/or consuming
287 1.1 paulus more output, and updating avail_in or avail_out accordingly; avail_out
288 1.1 paulus should never be zero before the call. The application can consume the
289 1.1 paulus compressed output when it wants, for example when the output buffer is full
290 1.1 paulus (avail_out == 0), or after each call of deflate().
291 1.1 paulus
292 1.1 paulus If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
293 1.1 paulus block is terminated and flushed to the output buffer so that the
294 1.1 paulus decompressor can get all input data available so far. For method 9, a future
295 1.1 paulus variant on method 8, the current block will be flushed but not terminated.
296 1.1 paulus If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
297 1.1 paulus special marker is output and the compression dictionary is discarded; this
298 1.1 paulus is useful to allow the decompressor to synchronize if one compressed block
299 1.1 paulus has been damaged (see inflateSync below). Flushing degrades compression and
300 1.1 paulus so should be used only when necessary. Using Z_FULL_FLUSH too often can
301 1.1 paulus seriously degrade the compression. If deflate returns with avail_out == 0,
302 1.1 paulus this function must be called again with the same value of the flush
303 1.1 paulus parameter and more output space (updated avail_out), until the flush is
304 1.1 paulus complete (deflate returns with non-zero avail_out).
305 1.1 paulus
306 1.1 paulus If the parameter flush is set to Z_PACKET_FLUSH, the compression
307 1.1 paulus block is terminated, and a zero-length stored block is output,
308 1.1 paulus omitting the length bytes (the effect of this is that the 3-bit type
309 1.1 paulus code 000 for a stored block is output, and the output is then
310 1.1 paulus byte-aligned). This is designed for use at the end of a PPP packet.
311 1.1 paulus In addition, if the current compression block contains all the data
312 1.1 paulus since the last Z_PACKET_FLUSH, it is never output as a stored block.
313 1.1 paulus If the current compression block output as a static or dynamic block
314 1.1 paulus would not be at least `minCompression' bytes smaller than the
315 1.1 paulus original data, then nothing is output for that block. (The type
316 1.1 paulus code for the zero-length stored block is still output, resulting in
317 1.1 paulus a single zero byte being output for the whole packet.)
318 1.1 paulus `MinCompression' is a parameter to deflateInit2, or 0 if deflateInit
319 1.1 paulus is used.
320 1.1 paulus
321 1.1 paulus If the parameter flush is set to Z_FINISH, all pending input is processed,
322 1.1 paulus all pending output is flushed and deflate returns with Z_STREAM_END if there
323 1.1 paulus was enough output space; if deflate returns with Z_OK, this function must be
324 1.1 paulus called again with Z_FINISH and more output space (updated avail_out) but no
325 1.1 paulus more input data, until it returns with Z_STREAM_END or an error. After
326 1.1 paulus deflate has returned Z_STREAM_END, the only possible operations on the
327 1.1 paulus stream are deflateReset or deflateEnd.
328 1.1 paulus
329 1.1 paulus Z_FINISH can be used immediately after deflateInit if all the compression
330 1.1 paulus is to be done in a single step. In this case, avail_out must be at least
331 1.1 paulus 0.1% larger than avail_in plus 12 bytes. If deflate does not return
332 1.1 paulus Z_STREAM_END, then it must be called again as described above.
333 1.1 paulus
334 1.1 paulus deflate() may update data_type if it can make a good guess about
335 1.1 paulus the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
336 1.1 paulus binary. This field is only for information purposes and does not affect
337 1.1 paulus the compression algorithm in any manner.
338 1.1 paulus
339 1.1 paulus deflate() returns Z_OK if some progress has been made (more input
340 1.1 paulus processed or more output produced), Z_STREAM_END if all input has been
341 1.1 paulus consumed and all output has been produced (only when flush is set to
342 1.1 paulus Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
343 1.1 paulus if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
344 1.1 paulus */
345 1.1 paulus
346 1.1 paulus
347 1.1 paulus extern int deflateEnd OF((z_stream *strm));
348 1.1 paulus /*
349 1.1 paulus All dynamically allocated data structures for this stream are freed.
350 1.1 paulus This function discards any unprocessed input and does not flush any
351 1.1 paulus pending output.
352 1.1 paulus
353 1.1 paulus deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
354 1.1 paulus stream state was inconsistent. In the error case, msg may be set
355 1.1 paulus but then points to a static string (which must not be deallocated).
356 1.1 paulus */
357 1.1 paulus
358 1.1 paulus
359 1.1 paulus extern int inflateInit OF((z_stream *strm));
360 1.1 paulus /*
361 1.1 paulus Initializes the internal stream state for decompression. The fields
362 1.1 paulus zalloc and zfree must be initialized before by the caller. If zalloc and
363 1.1 paulus zfree are set to Z_NULL, inflateInit updates them to use default allocation
364 1.1 paulus functions.
365 1.1 paulus
366 1.1 paulus inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
367 1.1 paulus enough memory. msg is set to null if there is no error message.
368 1.1 paulus inflateInit does not perform any decompression: this will be done by
369 1.1 paulus inflate().
370 1.1 paulus */
371 1.1 paulus
372 1.1 paulus
373 1.1 paulus extern int inflate OF((z_stream *strm, int flush));
374 1.1 paulus /*
375 1.1 paulus Performs one or both of the following actions:
376 1.1 paulus
377 1.1 paulus - Decompress more input starting at next_in and update next_in and avail_in
378 1.1 paulus accordingly. If not all input can be processed (because there is not
379 1.1 paulus enough room in the output buffer), next_in is updated and processing
380 1.1 paulus will resume at this point for the next call of inflate().
381 1.1 paulus
382 1.1 paulus - Provide more output starting at next_out and update next_out and avail_out
383 1.1 paulus accordingly. inflate() always provides as much output as possible
384 1.1 paulus (until there is no more input data or no more space in the output buffer).
385 1.1 paulus
386 1.1 paulus Before the call of inflate(), the application should ensure that at least
387 1.1 paulus one of the actions is possible, by providing more input and/or consuming
388 1.1 paulus more output, and updating the next_* and avail_* values accordingly.
389 1.1 paulus The application can consume the uncompressed output when it wants, for
390 1.1 paulus example when the output buffer is full (avail_out == 0), or after each
391 1.1 paulus call of inflate().
392 1.1 paulus
393 1.1 paulus If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
394 1.1 paulus inflate flushes as much output as possible to the output buffer. The
395 1.1 paulus flushing behavior of inflate is not specified for values of the flush
396 1.1 paulus parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
397 1.1 paulus current implementation actually flushes as much output as possible
398 1.1 paulus anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data
399 1.1 paulus has been consumed, it is expecting to see the length field of a stored
400 1.1 paulus block; if not, it returns Z_DATA_ERROR.
401 1.1 paulus
402 1.1 paulus inflate() should normally be called until it returns Z_STREAM_END or an
403 1.1 paulus error. However if all decompression is to be performed in a single step
404 1.1 paulus (a single call of inflate), the parameter flush should be set to
405 1.1 paulus Z_FINISH. In this case all pending input is processed and all pending
406 1.1 paulus output is flushed; avail_out must be large enough to hold all the
407 1.1 paulus uncompressed data. (The size of the uncompressed data may have been saved
408 1.1 paulus by the compressor for this purpose.) The next operation on this stream must
409 1.1 paulus be inflateEnd to deallocate the decompression state. The use of Z_FINISH
410 1.1 paulus is never required, but can be used to inform inflate that a faster routine
411 1.1 paulus may be used for the single inflate() call.
412 1.1 paulus
413 1.1 paulus inflate() returns Z_OK if some progress has been made (more input
414 1.1 paulus processed or more output produced), Z_STREAM_END if the end of the
415 1.1 paulus compressed data has been reached and all uncompressed output has been
416 1.1 paulus produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
417 1.1 paulus the stream structure was inconsistent (for example if next_in or next_out
418 1.1 paulus was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
419 1.1 paulus progress is possible or if there was not enough room in the output buffer
420 1.1 paulus when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
421 1.1 paulus call inflateSync to look for a good compression block. */
422 1.1 paulus
423 1.1 paulus
424 1.1 paulus extern int inflateEnd OF((z_stream *strm));
425 1.1 paulus /*
426 1.1 paulus All dynamically allocated data structures for this stream are freed.
427 1.1 paulus This function discards any unprocessed input and does not flush any
428 1.1 paulus pending output.
429 1.1 paulus
430 1.1 paulus inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
431 1.1 paulus was inconsistent. In the error case, msg may be set but then points to a
432 1.1 paulus static string (which must not be deallocated).
433 1.1 paulus */
434 1.1 paulus
435 1.1 paulus /* advanced functions */
436 1.1 paulus
437 1.1 paulus /*
438 1.1 paulus The following functions are needed only in some special applications.
439 1.1 paulus */
440 1.1 paulus
441 1.1 paulus extern int deflateInit2 OF((z_stream *strm,
442 1.1 paulus int level,
443 1.1 paulus int method,
444 1.1 paulus int windowBits,
445 1.1 paulus int memLevel,
446 1.1 paulus int strategy,
447 1.1 paulus int minCompression));
448 1.1 paulus /*
449 1.1 paulus This is another version of deflateInit with more compression options. The
450 1.1 paulus fields next_in, zalloc and zfree must be initialized before by the caller.
451 1.1 paulus
452 1.1 paulus The method parameter is the compression method. It must be 8 in this
453 1.1 paulus version of the library. (Method 9 will allow a 64K history buffer and
454 1.1 paulus partial block flushes.)
455 1.1 paulus
456 1.1 paulus The windowBits parameter is the base two logarithm of the window size
457 1.1 paulus (the size of the history buffer). It should be in the range 8..15 for this
458 1.1 paulus version of the library (the value 16 will be allowed for method 9). Larger
459 1.1 paulus values of this parameter result in better compression at the expense of
460 1.1 paulus memory usage. The default value is 15 if deflateInit is used instead.
461 1.1 paulus
462 1.1 paulus The memLevel parameter specifies how much memory should be allocated
463 1.1 paulus for the internal compression state. memLevel=1 uses minimum memory but
464 1.1 paulus is slow and reduces compression ratio; memLevel=9 uses maximum memory
465 1.1 paulus for optimal speed. The default value is 8. See zconf.h for total memory
466 1.1 paulus usage as a function of windowBits and memLevel.
467 1.1 paulus
468 1.1 paulus The strategy parameter is used to tune the compression algorithm. Use
469 1.1 paulus the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
470 1.1 paulus produced by a filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman
471 1.1 paulus encoding only (no string match). Filtered data consists mostly of small
472 1.1 paulus values with a somewhat random distribution. In this case, the
473 1.1 paulus compression algorithm is tuned to compress them better. The strategy
474 1.1 paulus parameter only affects the compression ratio but not the correctness of
475 1.1 paulus the compressed output even if it is not set appropriately.
476 1.1 paulus
477 1.1 paulus The minCompression parameter specifies the minimum reduction in size
478 1.1 paulus required for a compressed block to be output when Z_PACKET_FLUSH is
479 1.1 paulus used (see the description of deflate above).
480 1.1 paulus
481 1.1 paulus If next_in is not null, the library will use this buffer to hold also
482 1.1 paulus some history information; the buffer must either hold the entire input
483 1.1 paulus data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
484 1.1 paulus is null, the library will allocate its own history buffer (and leave next_in
485 1.1 paulus null). next_out need not be provided here but must be provided by the
486 1.1 paulus application for the next call of deflate().
487 1.1 paulus
488 1.1 paulus If the history buffer is provided by the application, next_in must
489 1.1 paulus must never be changed by the application since the compressor maintains
490 1.1 paulus information inside this buffer from call to call; the application
491 1.1 paulus must provide more input only by increasing avail_in. next_in is always
492 1.1 paulus reset by the library in this case.
493 1.1 paulus
494 1.1 paulus deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
495 1.1 paulus not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
496 1.1 paulus an invalid method). msg is set to null if there is no error message.
497 1.1 paulus deflateInit2 does not perform any compression: this will be done by
498 1.1 paulus deflate().
499 1.1 paulus */
500 1.1 paulus
501 1.1 paulus extern int deflateCopy OF((z_stream *dest,
502 1.1 paulus z_stream *source));
503 1.1 paulus /*
504 1.1 paulus Sets the destination stream as a complete copy of the source stream. If
505 1.1 paulus the source stream is using an application-supplied history buffer, a new
506 1.1 paulus buffer is allocated for the destination stream. The compressed output
507 1.1 paulus buffer is always application-supplied. It's the responsibility of the
508 1.1 paulus application to provide the correct values of next_out and avail_out for the
509 1.1 paulus next call of deflate.
510 1.1 paulus
511 1.1 paulus This function is useful when several compression strategies will be
512 1.1 paulus tried, for example when there are several ways of pre-processing the input
513 1.1 paulus data with a filter. The streams that will be discarded should then be freed
514 1.1 paulus by calling deflateEnd. Note that deflateCopy duplicates the internal
515 1.1 paulus compression state which can be quite large, so this strategy is slow and
516 1.1 paulus can consume lots of memory.
517 1.1 paulus
518 1.1 paulus deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
519 1.1 paulus enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
520 1.1 paulus (such as zalloc being NULL). msg is left unchanged in both source and
521 1.1 paulus destination.
522 1.1 paulus */
523 1.1 paulus
524 1.1 paulus extern int deflateReset OF((z_stream *strm));
525 1.1 paulus /*
526 1.1 paulus This function is equivalent to deflateEnd followed by deflateInit,
527 1.1 paulus but does not free and reallocate all the internal compression state.
528 1.1 paulus The stream will keep the same compression level and any other attributes
529 1.1 paulus that may have been set by deflateInit2.
530 1.1 paulus
531 1.1 paulus deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
532 1.1 paulus stream state was inconsistent (such as zalloc or state being NULL).
533 1.1 paulus */
534 1.1 paulus
535 1.1 paulus extern int inflateInit2 OF((z_stream *strm,
536 1.1 paulus int windowBits));
537 1.1 paulus /*
538 1.1 paulus This is another version of inflateInit with more compression options. The
539 1.1 paulus fields next_out, zalloc and zfree must be initialized before by the caller.
540 1.1 paulus
541 1.1 paulus The windowBits parameter is the base two logarithm of the maximum window
542 1.1 paulus size (the size of the history buffer). It should be in the range 8..15 for
543 1.1 paulus this version of the library (the value 16 will be allowed soon). The
544 1.1 paulus default value is 15 if inflateInit is used instead. If a compressed stream
545 1.1 paulus with a larger window size is given as input, inflate() will return with
546 1.1 paulus the error code Z_DATA_ERROR instead of trying to allocate a larger window.
547 1.1 paulus
548 1.1 paulus If next_out is not null, the library will use this buffer for the history
549 1.1 paulus buffer; the buffer must either be large enough to hold the entire output
550 1.1 paulus data, or have at least 1<<windowBits bytes. If next_out is null, the
551 1.1 paulus library will allocate its own buffer (and leave next_out null). next_in
552 1.1 paulus need not be provided here but must be provided by the application for the
553 1.1 paulus next call of inflate().
554 1.1 paulus
555 1.1 paulus If the history buffer is provided by the application, next_out must
556 1.1 paulus never be changed by the application since the decompressor maintains
557 1.1 paulus history information inside this buffer from call to call; the application
558 1.1 paulus can only reset next_out to the beginning of the history buffer when
559 1.1 paulus avail_out is zero and all output has been consumed.
560 1.1 paulus
561 1.1 paulus inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
562 1.1 paulus not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
563 1.1 paulus windowBits < 8). msg is set to null if there is no error message.
564 1.1 paulus inflateInit2 does not perform any decompression: this will be done by
565 1.1 paulus inflate().
566 1.1 paulus */
567 1.1 paulus
568 1.1 paulus extern int inflateSync OF((z_stream *strm));
569 1.1 paulus /*
570 1.1 paulus Skips invalid compressed data until the special marker (see deflate()
571 1.1 paulus above) can be found, or until all available input is skipped. No output
572 1.1 paulus is provided.
573 1.1 paulus
574 1.1 paulus inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
575 1.1 paulus if no more input was provided, Z_DATA_ERROR if no marker has been found,
576 1.1 paulus or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
577 1.1 paulus case, the application may save the current current value of total_in which
578 1.1 paulus indicates where valid compressed data was found. In the error case, the
579 1.1 paulus application may repeatedly call inflateSync, providing more input each time,
580 1.1 paulus until success or end of the input data.
581 1.1 paulus */
582 1.1 paulus
583 1.1 paulus extern int inflateReset OF((z_stream *strm));
584 1.1 paulus /*
585 1.1 paulus This function is equivalent to inflateEnd followed by inflateInit,
586 1.1 paulus but does not free and reallocate all the internal decompression state.
587 1.1 paulus The stream will keep attributes that may have been set by inflateInit2.
588 1.1 paulus
589 1.1 paulus inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
590 1.1 paulus stream state was inconsistent (such as zalloc or state being NULL).
591 1.1 paulus */
592 1.1 paulus
593 1.1 paulus extern int inflateIncomp OF((z_stream *strm));
594 1.1 paulus /*
595 1.1 paulus This function adds the data at next_in (avail_in bytes) to the output
596 1.1 paulus history without performing any output. There must be no pending output,
597 1.1 paulus and the decompressor must be expecting to see the start of a block.
598 1.1 paulus Calling this function is equivalent to decompressing a stored block
599 1.1 paulus containing the data at next_in (except that the data is not output).
600 1.1 paulus */
601 1.1 paulus
602 1.1 paulus /* checksum functions */
603 1.1 paulus
604 1.1 paulus /*
605 1.1 paulus This function is not related to compression but is exported
606 1.1 paulus anyway because it might be useful in applications using the
607 1.1 paulus compression library.
608 1.1 paulus */
609 1.1 paulus
610 1.1 paulus extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
611 1.1 paulus
612 1.1 paulus /*
613 1.1 paulus Update a running Adler-32 checksum with the bytes buf[0..len-1] and
614 1.1 paulus return the updated checksum. If buf is NULL, this function returns
615 1.1 paulus the required initial value for the checksum.
616 1.1 paulus An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
617 1.1 paulus much faster. Usage example:
618 1.1 paulus
619 1.1 paulus uLong adler = adler32(0L, Z_NULL, 0);
620 1.1 paulus
621 1.1 paulus while (read_buffer(buffer, length) != EOF) {
622 1.1 paulus adler = adler32(adler, buffer, length);
623 1.1 paulus }
624 1.1 paulus if (adler != original_adler) error();
625 1.1 paulus */
626 1.1 paulus
627 1.1 paulus #ifndef _Z_UTIL_H
628 1.1 paulus struct internal_state {int dummy;}; /* hack for buggy compilers */
629 1.1 paulus #endif
630 1.1 paulus
631 1.1 paulus #endif /* _ZLIB_H */
632