1.1 --- a/epoc32/include/ezlib.h Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/ezlib.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,924 +1,29 @@
1.4 -/* zlib.h -- interface of the 'zlib' general purpose compression library
1.5 - version 1.1.3, July 9th, 1998
1.6 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +// All rights reserved.
1.8 +// This component and the accompanying materials are made available
1.9 +// under the terms of "Eclipse Public License v1.0"
1.10 +// which accompanies this distribution, and is available
1.11 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 +//
1.13 +// Initial Contributors:
1.14 +// Nokia Corporation - initial contribution.
1.15 +//
1.16 +// Contributors:
1.17 +//
1.18 +// Description:
1.19 +//
1.20
1.21 - Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
1.22 +#ifndef EZLIB_H
1.23 +#define EZLIB_H
1.24
1.25 - This software is provided 'as-is', without any express or implied
1.26 - warranty. In no event will the authors be held liable for any damages
1.27 - arising from the use of this software.
1.28 -
1.29 - Permission is granted to anyone to use this software for any purpose,
1.30 - including commercial applications, and to alter it and redistribute it
1.31 - freely, subject to the following restrictions:
1.32 -
1.33 - 1. The origin of this software must not be misrepresented; you must not
1.34 - claim that you wrote the original software. If you use this software
1.35 - in a product, an acknowledgment in the product documentation would be
1.36 - appreciated but is not required.
1.37 - 2. Altered source versions must be plainly marked as such, and must not be
1.38 - misrepresented as being the original software.
1.39 - 3. This notice may not be removed or altered from any source distribution.
1.40 -
1.41 - Jean-loup Gailly Mark Adler
1.42 - jloup@gzip.org madler@alumni.caltech.edu
1.43 -
1.44 -
1.45 - The data format used by the zlib library is described by RFCs (Request for
1.46 - Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
1.47 - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
1.48 +/**
1.49 +@file
1.50 +@publishedAll
1.51 +@externallyDefinedApi
1.52 */
1.53
1.54 -/*
1.55 -This is an altered version of the zlib library designed to run on EPOC
1.56 -Symbian Markr 5/11/99
1.57 -*/
1.58 +#include <ezconf.h>
1.59 +#include <zlib.h>
1.60
1.61 -#ifndef _ZLIB_H
1.62 -#define _ZLIB_H
1.63 +#endif // EZLIB_H
1.64
1.65 -#ifdef __cplusplus
1.66 -extern "C" {
1.67 -#endif
1.68 -
1.69 -#include <ezconf.h>
1.70 -
1.71 -#define ZLIB_VERSION "1.1.3"
1.72 -
1.73 -/*
1.74 - The 'zlib' compression library provides in-memory compression and
1.75 - decompression functions, including integrity checks of the uncompressed
1.76 - data. This version of the library supports only one compression method
1.77 - (deflation) but other algorithms will be added later and will have the same
1.78 - stream interface.
1.79 -
1.80 - Compression can be done in a single step if the buffers are large
1.81 - enough (for example if an input file is mmap'ed), or can be done by
1.82 - repeated calls of the compression function. In the latter case, the
1.83 - application must provide more input and/or consume the output
1.84 - (providing more output space) before each call.
1.85 -
1.86 - The library also supports reading and writing files in gzip (.gz) format
1.87 - with an interface similar to that of stdio.
1.88 -
1.89 - The library does not install any signal handler. The decoder checks
1.90 - the consistency of the compressed data, so the library should never
1.91 - crash even in case of corrupted input.
1.92 -*/
1.93 -
1.94 -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
1.95 -typedef void (*free_func) OF((voidpf opaque, voidpf address));
1.96 -
1.97 -struct internal_state;
1.98 -
1.99 -/**
1.100 -Encapsulates a zip stream
1.101 -
1.102 -@publishedAll
1.103 -@released
1.104 -*/
1.105 -typedef struct z_stream_s {
1.106 - /** next input byte */
1.107 - Bytef *next_in;
1.108 - /** number of bytes available at next_in */
1.109 - uInt avail_in;
1.110 - /** total nb of input bytes read so far */
1.111 - uLong total_in;
1.112 -
1.113 - /** next output byte should be put there */
1.114 - Bytef *next_out;
1.115 - /** remaining free space at next_out */
1.116 - uInt avail_out;
1.117 - /** total nb of bytes output so far */
1.118 - uLong total_out;
1.119 -
1.120 - /** last error message, NULL if no error */
1.121 - char *msg;
1.122 - /* not visible by applications */
1.123 - struct internal_state FAR *state;
1.124 -
1.125 - /** used to allocate the internal state */
1.126 - alloc_func zalloc;
1.127 - /** used to free the internal state */
1.128 - free_func zfree;
1.129 - /** private data object passed to zalloc and zfree */
1.130 - voidpf opaque;
1.131 -
1.132 - /** best guess about the data type: ascii or binary */
1.133 - int data_type;
1.134 - /** adler32 value of the uncompressed data */
1.135 - uLong adler;
1.136 - /** reserved for future use */
1.137 - uLong reserved;
1.138 -} z_stream;
1.139 -
1.140 -typedef z_stream FAR *z_streamp;
1.141 -
1.142 -/*
1.143 - The application must update next_in and avail_in when avail_in has
1.144 - dropped to zero. It must update next_out and avail_out when avail_out
1.145 - has dropped to zero. The application must initialize zalloc, zfree and
1.146 - opaque before calling the init function. All other fields are set by the
1.147 - compression library and must not be updated by the application.
1.148 -
1.149 - The opaque value provided by the application will be passed as the first
1.150 - parameter for calls of zalloc and zfree. This can be useful for custom
1.151 - memory management. The compression library attaches no meaning to the
1.152 - opaque value.
1.153 -
1.154 - zalloc must return Z_NULL if there is not enough memory for the object.
1.155 - If zlib is used in a multi-threaded application, zalloc and zfree must be
1.156 - thread safe.
1.157 -
1.158 - On 16-bit systems, the functions zalloc and zfree must be able to allocate
1.159 - exactly 65536 bytes, but will not be required to allocate more than this
1.160 - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
1.161 - pointers returned by zalloc for objects of exactly 65536 bytes *must*
1.162 - have their offset normalized to zero. The default allocation function
1.163 - provided by this library ensures this (see zutil.c). To reduce memory
1.164 - requirements and avoid any allocation of 64K objects, at the expense of
1.165 - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
1.166 -
1.167 - The fields total_in and total_out can be used for statistics or
1.168 - progress reports. After compression, total_in holds the total size of
1.169 - the uncompressed data and may be saved for use in the decompressor
1.170 - (particularly if the decompressor wants to decompress everything in
1.171 - a single step).
1.172 -*/
1.173 -
1.174 - /* constants */
1.175 -
1.176 -#define Z_NO_FLUSH 0
1.177 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
1.178 -#define Z_SYNC_FLUSH 2
1.179 -#define Z_FULL_FLUSH 3
1.180 -#define Z_FINISH 4
1.181 -/* Allowed flush values; see deflate() below for details */
1.182 -
1.183 -#define Z_OK 0
1.184 -#define Z_STREAM_END 1
1.185 -#define Z_NEED_DICT 2
1.186 -#define Z_ERRNO (-1)
1.187 -#define Z_STREAM_ERROR (-2)
1.188 -#define Z_DATA_ERROR (-3)
1.189 -#define Z_MEM_ERROR (-4)
1.190 -#define Z_BUF_ERROR (-5)
1.191 -#define Z_VERSION_ERROR (-6)
1.192 -/* Return codes for the compression/decompression functions. Negative
1.193 - * values are errors, positive values are used for special but normal events.
1.194 - */
1.195 -
1.196 -#define Z_NO_COMPRESSION 0
1.197 -#define Z_BEST_SPEED 1
1.198 -#define Z_BEST_COMPRESSION 9
1.199 -#define Z_DEFAULT_COMPRESSION (-1)
1.200 -/* compression levels */
1.201 -
1.202 -#define Z_FILTERED 1
1.203 -#define Z_HUFFMAN_ONLY 2
1.204 -#define Z_DEFAULT_STRATEGY 0
1.205 -/* compression strategy; see deflateInit2() below for details */
1.206 -
1.207 -#define Z_BINARY 0
1.208 -#define Z_ASCII 1
1.209 -#define Z_UNKNOWN 2
1.210 -/* Possible values of the data_type field */
1.211 -
1.212 -#define Z_DEFLATED 8
1.213 -/* The deflate compression method (the only one supported in this version) */
1.214 -
1.215 -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
1.216 -
1.217 -#define zlib_version zlibVersion()
1.218 -/* for compatibility with versions < 1.0.2 */
1.219 -
1.220 - /* basic functions */
1.221 -
1.222 -ZEXTERN const char * ZEXPORT zlibVersion OF((void));
1.223 -/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
1.224 - If the first character differs, the library code actually used is
1.225 - not compatible with the zlib.h header file used by the application.
1.226 - This check is automatically made by deflateInit and inflateInit.
1.227 - */
1.228 -
1.229 -/*
1.230 -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
1.231 -
1.232 - Initializes the internal stream state for compression. The fields
1.233 - zalloc, zfree and opaque must be initialized before by the caller.
1.234 - If zalloc and zfree are set to Z_NULL, deflateInit updates them to
1.235 - use default allocation functions.
1.236 -
1.237 - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1.238 - 1 gives best speed, 9 gives best compression, 0 gives no compression at
1.239 - all (the input data is simply copied a block at a time).
1.240 - Z_DEFAULT_COMPRESSION requests a default compromise between speed and
1.241 - compression (currently equivalent to level 6).
1.242 -
1.243 - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
1.244 - enough memory, Z_STREAM_ERROR if level is not a valid compression level,
1.245 - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
1.246 - with the version assumed by the caller (ZLIB_VERSION).
1.247 - msg is set to null if there is no error message. deflateInit does not
1.248 - perform any compression: this will be done by deflate().
1.249 -*/
1.250 -
1.251 -
1.252 -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
1.253 -/*
1.254 - deflate compresses as much data as possible, and stops when the input
1.255 - buffer becomes empty or the output buffer becomes full. It may introduce some
1.256 - output latency (reading input without producing any output) except when
1.257 - forced to flush.
1.258 -
1.259 - The detailed semantics are as follows. deflate performs one or both of the
1.260 - following actions:
1.261 -
1.262 - - Compress more input starting at next_in and update next_in and avail_in
1.263 - accordingly. If not all input can be processed (because there is not
1.264 - enough room in the output buffer), next_in and avail_in are updated and
1.265 - processing will resume at this point for the next call of deflate().
1.266 -
1.267 - - Provide more output starting at next_out and update next_out and avail_out
1.268 - accordingly. This action is forced if the parameter flush is non zero.
1.269 - Forcing flush frequently degrades the compression ratio, so this parameter
1.270 - should be set only when necessary (in interactive applications).
1.271 - Some output may be provided even if flush is not set.
1.272 -
1.273 - Before the call of deflate(), the application should ensure that at least
1.274 - one of the actions is possible, by providing more input and/or consuming
1.275 - more output, and updating avail_in or avail_out accordingly; avail_out
1.276 - should never be zero before the call. The application can consume the
1.277 - compressed output when it wants, for example when the output buffer is full
1.278 - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
1.279 - and with zero avail_out, it must be called again after making room in the
1.280 - output buffer because there might be more output pending.
1.281 -
1.282 - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
1.283 - flushed to the output buffer and the output is aligned on a byte boundary, so
1.284 - that the decompressor can get all input data available so far. (In particular
1.285 - avail_in is zero after the call if enough output space has been provided
1.286 - before the call.) Flushing may degrade compression for some compression
1.287 - algorithms and so it should be used only when necessary.
1.288 -
1.289 - If flush is set to Z_FULL_FLUSH, all output is flushed as with
1.290 - Z_SYNC_FLUSH, and the compression state is reset so that decompression can
1.291 - restart from this point if previous compressed data has been damaged or if
1.292 - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
1.293 - the compression.
1.294 -
1.295 - If deflate returns with avail_out == 0, this function must be called again
1.296 - with the same value of the flush parameter and more output space (updated
1.297 - avail_out), until the flush is complete (deflate returns with non-zero
1.298 - avail_out).
1.299 -
1.300 - If the parameter flush is set to Z_FINISH, pending input is processed,
1.301 - pending output is flushed and deflate returns with Z_STREAM_END if there
1.302 - was enough output space; if deflate returns with Z_OK, this function must be
1.303 - called again with Z_FINISH and more output space (updated avail_out) but no
1.304 - more input data, until it returns with Z_STREAM_END or an error. After
1.305 - deflate has returned Z_STREAM_END, the only possible operations on the
1.306 - stream are deflateReset or deflateEnd.
1.307 -
1.308 - Z_FINISH can be used immediately after deflateInit if all the compression
1.309 - is to be done in a single step. In this case, avail_out must be at least
1.310 - 0.1% larger than avail_in plus 12 bytes. If deflate does not return
1.311 - Z_STREAM_END, then it must be called again as described above.
1.312 -
1.313 - deflate() sets strm->adler to the adler32 checksum of all input read
1.314 - so far (that is, total_in bytes).
1.315 -
1.316 - deflate() may update data_type if it can make a good guess about
1.317 - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
1.318 - binary. This field is only for information purposes and does not affect
1.319 - the compression algorithm in any manner.
1.320 -
1.321 - deflate() returns Z_OK if some progress has been made (more input
1.322 - processed or more output produced), Z_STREAM_END if all input has been
1.323 - consumed and all output has been produced (only when flush is set to
1.324 - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
1.325 - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
1.326 - (for example avail_in or avail_out was zero).
1.327 -*/
1.328 -
1.329 -
1.330 -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
1.331 -/*
1.332 - All dynamically allocated data structures for this stream are freed.
1.333 - This function discards any unprocessed input and does not flush any
1.334 - pending output.
1.335 -
1.336 - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
1.337 - stream state was inconsistent, Z_DATA_ERROR if the stream was freed
1.338 - prematurely (some input or output was discarded). In the error case,
1.339 - msg may be set but then points to a static string (which must not be
1.340 - deallocated).
1.341 -*/
1.342 -
1.343 -
1.344 -/*
1.345 -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
1.346 -
1.347 - Initializes the internal stream state for decompression. The fields
1.348 - next_in, avail_in, zalloc, zfree and opaque must be initialized before by
1.349 - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
1.350 - value depends on the compression method), inflateInit determines the
1.351 - compression method from the zlib header and allocates all data structures
1.352 - accordingly; otherwise the allocation will be deferred to the first call of
1.353 - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
1.354 - use default allocation functions.
1.355 -
1.356 - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
1.357 - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
1.358 - version assumed by the caller. msg is set to null if there is no error
1.359 - message. inflateInit does not perform any decompression apart from reading
1.360 - the zlib header if present: this will be done by inflate(). (So next_in and
1.361 - avail_in may be modified, but next_out and avail_out are unchanged.)
1.362 -*/
1.363 -
1.364 -
1.365 -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
1.366 -/*
1.367 - inflate decompresses as much data as possible, and stops when the input
1.368 - buffer becomes empty or the output buffer becomes full. It may some
1.369 - introduce some output latency (reading input without producing any output)
1.370 - except when forced to flush.
1.371 -
1.372 - The detailed semantics are as follows. inflate performs one or both of the
1.373 - following actions:
1.374 -
1.375 - - Decompress more input starting at next_in and update next_in and avail_in
1.376 - accordingly. If not all input can be processed (because there is not
1.377 - enough room in the output buffer), next_in is updated and processing
1.378 - will resume at this point for the next call of inflate().
1.379 -
1.380 - - Provide more output starting at next_out and update next_out and avail_out
1.381 - accordingly. inflate() provides as much output as possible, until there
1.382 - is no more input data or no more space in the output buffer (see below
1.383 - about the flush parameter).
1.384 -
1.385 - Before the call of inflate(), the application should ensure that at least
1.386 - one of the actions is possible, by providing more input and/or consuming
1.387 - more output, and updating the next_* and avail_* values accordingly.
1.388 - The application can consume the uncompressed output when it wants, for
1.389 - example when the output buffer is full (avail_out == 0), or after each
1.390 - call of inflate(). If inflate returns Z_OK and with zero avail_out, it
1.391 - must be called again after making room in the output buffer because there
1.392 - might be more output pending.
1.393 -
1.394 - If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
1.395 - output as possible to the output buffer. The flushing behavior of inflate is
1.396 - not specified for values of the flush parameter other than Z_SYNC_FLUSH
1.397 - and Z_FINISH, but the current implementation actually flushes as much output
1.398 - as possible anyway.
1.399 -
1.400 - inflate() should normally be called until it returns Z_STREAM_END or an
1.401 - error. However if all decompression is to be performed in a single step
1.402 - (a single call of inflate), the parameter flush should be set to
1.403 - Z_FINISH. In this case all pending input is processed and all pending
1.404 - output is flushed; avail_out must be large enough to hold all the
1.405 - uncompressed data. (The size of the uncompressed data may have been saved
1.406 - by the compressor for this purpose.) The next operation on this stream must
1.407 - be inflateEnd to deallocate the decompression state. The use of Z_FINISH
1.408 - is never required, but can be used to inform inflate that a faster routine
1.409 - may be used for the single inflate() call.
1.410 -
1.411 - If a preset dictionary is needed at this point (see inflateSetDictionary
1.412 - below), inflate sets strm-adler to the adler32 checksum of the
1.413 - dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
1.414 - it sets strm->adler to the adler32 checksum of all output produced
1.415 - so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
1.416 - an error code as described below. At the end of the stream, inflate()
1.417 - checks that its computed adler32 checksum is equal to that saved by the
1.418 - compressor and returns Z_STREAM_END only if the checksum is correct.
1.419 -
1.420 - inflate() returns Z_OK if some progress has been made (more input processed
1.421 - or more output produced), Z_STREAM_END if the end of the compressed data has
1.422 - been reached and all uncompressed output has been produced, Z_NEED_DICT if a
1.423 - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
1.424 - corrupted (input stream not conforming to the zlib format or incorrect
1.425 - adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
1.426 - (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
1.427 - enough memory, Z_BUF_ERROR if no progress is possible or if there was not
1.428 - enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
1.429 - case, the application may then call inflateSync to look for a good
1.430 - compression block.
1.431 -*/
1.432 -
1.433 -
1.434 -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
1.435 -/*
1.436 - All dynamically allocated data structures for this stream are freed.
1.437 - This function discards any unprocessed input and does not flush any
1.438 - pending output.
1.439 -
1.440 - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
1.441 - was inconsistent. In the error case, msg may be set but then points to a
1.442 - static string (which must not be deallocated).
1.443 -*/
1.444 -
1.445 - /* Advanced functions */
1.446 -
1.447 -/*
1.448 - The following functions are needed only in some special applications.
1.449 -*/
1.450 -
1.451 -/*
1.452 -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
1.453 - int level,
1.454 - int method,
1.455 - int windowBits,
1.456 - int memLevel,
1.457 - int strategy));
1.458 -
1.459 - This is another version of deflateInit with more compression options. The
1.460 - fields next_in, zalloc, zfree and opaque must be initialized before by
1.461 - the caller.
1.462 -
1.463 - The method parameter is the compression method. It must be Z_DEFLATED in
1.464 - this version of the library.
1.465 -
1.466 - The windowBits parameter is the base two logarithm of the window size
1.467 - (the size of the history buffer). It should be in the range 8..15 for this
1.468 - version of the library. Larger values of this parameter result in better
1.469 - compression at the expense of memory usage. The default value is 15 if
1.470 - deflateInit is used instead.
1.471 -
1.472 - The memLevel parameter specifies how much memory should be allocated
1.473 - for the internal compression state. memLevel=1 uses minimum memory but
1.474 - is slow and reduces compression ratio; memLevel=9 uses maximum memory
1.475 - for optimal speed. The default value is 8. See zconf.h for total memory
1.476 - usage as a function of windowBits and memLevel.
1.477 -
1.478 - The strategy parameter is used to tune the compression algorithm. Use the
1.479 - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
1.480 - filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
1.481 - string match). Filtered data consists mostly of small values with a
1.482 - somewhat random distribution. In this case, the compression algorithm is
1.483 - tuned to compress them better. The effect of Z_FILTERED is to force more
1.484 - Huffman coding and less string matching; it is somewhat intermediate
1.485 - between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
1.486 - the compression ratio but not the correctness of the compressed output even
1.487 - if it is not set appropriately.
1.488 -
1.489 - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1.490 - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
1.491 - method). msg is set to null if there is no error message. deflateInit2 does
1.492 - not perform any compression: this will be done by deflate().
1.493 -*/
1.494 -
1.495 -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
1.496 - const Bytef *dictionary,
1.497 - uInt dictLength));
1.498 -/*
1.499 - Initializes the compression dictionary from the given byte sequence
1.500 - without producing any compressed output. This function must be called
1.501 - immediately after deflateInit, deflateInit2 or deflateReset, before any
1.502 - call of deflate. The compressor and decompressor must use exactly the same
1.503 - dictionary (see inflateSetDictionary).
1.504 -
1.505 - The dictionary should consist of strings (byte sequences) that are likely
1.506 - to be encountered later in the data to be compressed, with the most commonly
1.507 - used strings preferably put towards the end of the dictionary. Using a
1.508 - dictionary is most useful when the data to be compressed is short and can be
1.509 - predicted with good accuracy; the data can then be compressed better than
1.510 - with the default empty dictionary.
1.511 -
1.512 - Depending on the size of the compression data structures selected by
1.513 - deflateInit or deflateInit2, a part of the dictionary may in effect be
1.514 - discarded, for example if the dictionary is larger than the window size in
1.515 - deflate or deflate2. Thus the strings most likely to be useful should be
1.516 - put at the end of the dictionary, not at the front.
1.517 -
1.518 - Upon return of this function, strm->adler is set to the Adler32 value
1.519 - of the dictionary; the decompressor may later use this value to determine
1.520 - which dictionary has been used by the compressor. (The Adler32 value
1.521 - applies to the whole dictionary even if only a subset of the dictionary is
1.522 - actually used by the compressor.)
1.523 -
1.524 - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
1.525 - parameter is invalid (such as NULL dictionary) or the stream state is
1.526 - inconsistent (for example if deflate has already been called for this stream
1.527 - or if the compression method is bsort). deflateSetDictionary does not
1.528 - perform any compression: this will be done by deflate().
1.529 -*/
1.530 -
1.531 -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
1.532 - z_streamp source));
1.533 -/*
1.534 - Sets the destination stream as a complete copy of the source stream.
1.535 -
1.536 - This function can be useful when several compression strategies will be
1.537 - tried, for example when there are several ways of pre-processing the input
1.538 - data with a filter. The streams that will be discarded should then be freed
1.539 - by calling deflateEnd. Note that deflateCopy duplicates the internal
1.540 - compression state which can be quite large, so this strategy is slow and
1.541 - can consume lots of memory.
1.542 -
1.543 - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
1.544 - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
1.545 - (such as zalloc being NULL). msg is left unchanged in both source and
1.546 - destination.
1.547 -*/
1.548 -
1.549 -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
1.550 -/*
1.551 - This function is equivalent to deflateEnd followed by deflateInit,
1.552 - but does not free and reallocate all the internal compression state.
1.553 - The stream will keep the same compression level and any other attributes
1.554 - that may have been set by deflateInit2.
1.555 -
1.556 - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
1.557 - stream state was inconsistent (such as zalloc or state being NULL).
1.558 -*/
1.559 -
1.560 -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
1.561 - int level,
1.562 - int strategy));
1.563 -/*
1.564 - Dynamically update the compression level and compression strategy. The
1.565 - interpretation of level and strategy is as in deflateInit2. This can be
1.566 - used to switch between compression and straight copy of the input data, or
1.567 - to switch to a different kind of input data requiring a different
1.568 - strategy. If the compression level is changed, the input available so far
1.569 - is compressed with the old level (and may be flushed); the new level will
1.570 - take effect only at the next call of deflate().
1.571 -
1.572 - Before the call of deflateParams, the stream state must be set as for
1.573 - a call of deflate(), since the currently available input may have to
1.574 - be compressed and flushed. In particular, strm->avail_out must be non-zero.
1.575 -
1.576 - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
1.577 - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
1.578 - if strm->avail_out was zero.
1.579 -*/
1.580 -
1.581 -/*
1.582 -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
1.583 - int windowBits));
1.584 -
1.585 - This is another version of inflateInit with an extra parameter. The
1.586 - fields next_in, avail_in, zalloc, zfree and opaque must be initialized
1.587 - before by the caller.
1.588 -
1.589 - The windowBits parameter is the base two logarithm of the maximum window
1.590 - size (the size of the history buffer). It should be in the range 8..15 for
1.591 - this version of the library. The default value is 15 if inflateInit is used
1.592 - instead. If a compressed stream with a larger window size is given as
1.593 - input, inflate() will return with the error code Z_DATA_ERROR instead of
1.594 - trying to allocate a larger window.
1.595 -
1.596 - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1.597 - memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
1.598 - memLevel). msg is set to null if there is no error message. inflateInit2
1.599 - does not perform any decompression apart from reading the zlib header if
1.600 - present: this will be done by inflate(). (So next_in and avail_in may be
1.601 - modified, but next_out and avail_out are unchanged.)
1.602 -*/
1.603 -
1.604 -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
1.605 - const Bytef *dictionary,
1.606 - uInt dictLength));
1.607 -/*
1.608 - Initializes the decompression dictionary from the given uncompressed byte
1.609 - sequence. This function must be called immediately after a call of inflate
1.610 - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
1.611 - can be determined from the Adler32 value returned by this call of
1.612 - inflate. The compressor and decompressor must use exactly the same
1.613 - dictionary (see deflateSetDictionary).
1.614 -
1.615 - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
1.616 - parameter is invalid (such as NULL dictionary) or the stream state is
1.617 - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
1.618 - expected one (incorrect Adler32 value). inflateSetDictionary does not
1.619 - perform any decompression: this will be done by subsequent calls of
1.620 - inflate().
1.621 -*/
1.622 -
1.623 -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
1.624 -/*
1.625 - Skips invalid compressed data until a full flush point (see above the
1.626 - description of deflate with Z_FULL_FLUSH) can be found, or until all
1.627 - available input is skipped. No output is provided.
1.628 -
1.629 - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
1.630 - if no more input was provided, Z_DATA_ERROR if no flush point has been found,
1.631 - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
1.632 - case, the application may save the current current value of total_in which
1.633 - indicates where valid compressed data was found. In the error case, the
1.634 - application may repeatedly call inflateSync, providing more input each time,
1.635 - until success or end of the input data.
1.636 -*/
1.637 -
1.638 -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
1.639 -/*
1.640 - This function is equivalent to inflateEnd followed by inflateInit,
1.641 - but does not free and reallocate all the internal decompression state.
1.642 - The stream will keep attributes that may have been set by inflateInit2.
1.643 -
1.644 - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
1.645 - stream state was inconsistent (such as zalloc or state being NULL).
1.646 -*/
1.647 -
1.648 -
1.649 - /* utility functions */
1.650 -
1.651 -/*
1.652 - The following utility functions are implemented on top of the
1.653 - basic stream-oriented functions. To simplify the interface, some
1.654 - default options are assumed (compression level and memory usage,
1.655 - standard memory allocation functions). The source code of these
1.656 - utility functions can easily be modified if you need special options.
1.657 -*/
1.658 -
1.659 -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1.660 - const Bytef *source, uLong sourceLen));
1.661 -/*
1.662 - Compresses the source buffer into the destination buffer. sourceLen is
1.663 - the byte length of the source buffer. Upon entry, destLen is the total
1.664 - size of the destination buffer, which must be at least 0.1% larger than
1.665 - sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
1.666 - compressed buffer.
1.667 - This function can be used to compress a whole file at once if the
1.668 - input file is mmap'ed.
1.669 - compress returns Z_OK if success, Z_MEM_ERROR if there was not
1.670 - enough memory, Z_BUF_ERROR if there was not enough room in the output
1.671 - buffer.
1.672 -*/
1.673 -
1.674 -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1.675 - const Bytef *source, uLong sourceLen,
1.676 - int level));
1.677 -/*
1.678 - Compresses the source buffer into the destination buffer. The level
1.679 - parameter has the same meaning as in deflateInit. sourceLen is the byte
1.680 - length of the source buffer. Upon entry, destLen is the total size of the
1.681 - destination buffer, which must be at least 0.1% larger than sourceLen plus
1.682 - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
1.683 -
1.684 - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1.685 - memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1.686 - Z_STREAM_ERROR if the level parameter is invalid.
1.687 -*/
1.688 -
1.689 -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1.690 - const Bytef *source, uLong sourceLen));
1.691 -/*
1.692 - Decompresses the source buffer into the destination buffer. sourceLen is
1.693 - the byte length of the source buffer. Upon entry, destLen is the total
1.694 - size of the destination buffer, which must be large enough to hold the
1.695 - entire uncompressed data. (The size of the uncompressed data must have
1.696 - been saved previously by the compressor and transmitted to the decompressor
1.697 - by some mechanism outside the scope of this compression library.)
1.698 - Upon exit, destLen is the actual size of the compressed buffer.
1.699 - This function can be used to decompress a whole file at once if the
1.700 - input file is mmap'ed.
1.701 -
1.702 - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1.703 - enough memory, Z_BUF_ERROR if there was not enough room in the output
1.704 - buffer, or Z_DATA_ERROR if the input data was corrupted.
1.705 -*/
1.706 -
1.707 -/*
1.708 -typedef voidp gzFile;
1.709 -
1.710 -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1.711 -*/
1.712 -/*
1.713 - Opens a gzip (.gz) file for reading or writing. The mode parameter
1.714 - is as in fopen ("rb" or "wb") but can also include a compression level
1.715 - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
1.716 - Huffman only compression as in "wb1h". (See the description
1.717 - of deflateInit2 for more information about the strategy parameter.)
1.718 -
1.719 - gzopen can be used to read a file which is not in gzip format; in this
1.720 - case gzread will directly read from the file without decompression.
1.721 -
1.722 - gzopen returns NULL if the file could not be opened or if there was
1.723 - insufficient memory to allocate the (de)compression state; errno
1.724 - can be checked to distinguish the two cases (if errno is zero, the
1.725 - zlib error is Z_MEM_ERROR). */
1.726 -
1.727 -//ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1.728 -
1.729 -/*
1.730 - gzdopen() associates a gzFile with the file descriptor fd. File
1.731 - descriptors are obtained from calls like open, dup, creat, pipe or
1.732 - fileno (in the file has been previously opened with fopen).
1.733 - The mode parameter is as in gzopen.
1.734 - The next call of gzclose on the returned gzFile will also close the
1.735 - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
1.736 - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
1.737 - gzdopen returns NULL if there was insufficient memory to allocate
1.738 - the (de)compression state.
1.739 -*/
1.740 -
1.741 -//ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1.742 -/*
1.743 - Dynamically update the compression level or strategy. See the description
1.744 - of deflateInit2 for the meaning of these parameters.
1.745 - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1.746 - opened for writing.
1.747 -*/
1.748 -
1.749 -//ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1.750 -/*
1.751 - Reads the given number of uncompressed bytes from the compressed file.
1.752 - If the input file was not in gzip format, gzread copies the given number
1.753 - of bytes into the buffer.
1.754 - gzread returns the number of uncompressed bytes actually read (0 for
1.755 - end of file, -1 for error). */
1.756 -
1.757 -//ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1.758 -// const voidp buf, unsigned len));
1.759 -/*
1.760 - Writes the given number of uncompressed bytes into the compressed file.
1.761 - gzwrite returns the number of uncompressed bytes actually written
1.762 - (0 in case of error).
1.763 -*/
1.764 -
1.765 -//ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
1.766 -/*
1.767 - Converts, formats, and writes the args to the compressed file under
1.768 - control of the format string, as in fprintf. gzprintf returns the number of
1.769 - uncompressed bytes actually written (0 in case of error).
1.770 -*/
1.771 -
1.772 -//ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1.773 -/*
1.774 - Writes the given null-terminated string to the compressed file, excluding
1.775 - the terminating null character.
1.776 - gzputs returns the number of characters written, or -1 in case of error.
1.777 -*/
1.778 -
1.779 -//ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1.780 -/*
1.781 - Reads bytes from the compressed file until len-1 characters are read, or
1.782 - a newline character is read and transferred to buf, or an end-of-file
1.783 - condition is encountered. The string is then terminated with a null
1.784 - character.
1.785 - gzgets returns buf, or Z_NULL in case of error.
1.786 -*/
1.787 -
1.788 -//ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1.789 -/*
1.790 - Writes c, converted to an unsigned char, into the compressed file.
1.791 - gzputc returns the value that was written, or -1 in case of error.
1.792 -*/
1.793 -
1.794 -//ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1.795 -/*
1.796 - Reads one byte from the compressed file. gzgetc returns this byte
1.797 - or -1 in case of end of file or error.
1.798 -*/
1.799 -
1.800 -//ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1.801 -/*
1.802 - Flushes all pending output into the compressed file. The parameter
1.803 - flush is as in the deflate() function. The return value is the zlib
1.804 - error number (see function gzerror below). gzflush returns Z_OK if
1.805 - the flush parameter is Z_FINISH and all output could be flushed.
1.806 - gzflush should be called only when strictly necessary because it can
1.807 - degrade compression.
1.808 -*/
1.809 -
1.810 -//ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1.811 -// z_off_t offset, int whence));
1.812 -/*
1.813 - Sets the starting position for the next gzread or gzwrite on the
1.814 - given compressed file. The offset represents a number of bytes in the
1.815 - uncompressed data stream. The whence parameter is defined as in lseek(2);
1.816 - the value SEEK_END is not supported.
1.817 - If the file is opened for reading, this function is emulated but can be
1.818 - extremely slow. If the file is opened for writing, only forward seeks are
1.819 - supported; gzseek then compresses a sequence of zeroes up to the new
1.820 - starting position.
1.821 -
1.822 - gzseek returns the resulting offset location as measured in bytes from
1.823 - the beginning of the uncompressed stream, or -1 in case of error, in
1.824 - particular if the file is opened for writing and the new starting position
1.825 - would be before the current position.
1.826 -*/
1.827 -
1.828 -//ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1.829 -/*
1.830 - Rewinds the given file. This function is supported only for reading.
1.831 -
1.832 - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1.833 -*/
1.834 -
1.835 -//ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1.836 -/*
1.837 - Returns the starting position for the next gzread or gzwrite on the
1.838 - given compressed file. This position represents a number of bytes in the
1.839 - uncompressed data stream.
1.840 -
1.841 - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1.842 -*/
1.843 -
1.844 -//ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1.845 -/*
1.846 - Returns 1 when EOF has previously been detected reading the given
1.847 - input stream, otherwise zero.
1.848 -*/
1.849 -
1.850 -//ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1.851 -/*
1.852 - Flushes all pending output if necessary, closes the compressed file
1.853 - and deallocates all the (de)compression state. The return value is the zlib
1.854 - error number (see function gzerror below).
1.855 -*/
1.856 -
1.857 -//ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1.858 -/*
1.859 - Returns the error message for the last error which occurred on the
1.860 - given compressed file. errnum is set to zlib error number. If an
1.861 - error occurred in the file system and not in the compression library,
1.862 - errnum is set to Z_ERRNO and the application may consult errno
1.863 - to get the exact error code.
1.864 -*/
1.865 -
1.866 - /* checksum functions */
1.867 -
1.868 -/*
1.869 - These functions are not related to compression but are exported
1.870 - anyway because they might be useful in applications using the
1.871 - compression library.
1.872 -*/
1.873 -
1.874 -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1.875 -
1.876 -/*
1.877 - Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1.878 - return the updated checksum. If buf is NULL, this function returns
1.879 - the required initial value for the checksum.
1.880 - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1.881 - much faster. Usage example:
1.882 -
1.883 - uLong adler = adler32(0L, Z_NULL, 0);
1.884 -
1.885 - while (read_buffer(buffer, length) != EOF) {
1.886 - adler = adler32(adler, buffer, length);
1.887 - }
1.888 - if (adler != original_adler) error();
1.889 -*/
1.890 -
1.891 -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1.892 -/*
1.893 - Update a running crc with the bytes buf[0..len-1] and return the updated
1.894 - crc. If buf is NULL, this function returns the required initial value
1.895 - for the crc. Pre- and post-conditioning (one's complement) is performed
1.896 - within this function so it shouldn't be done by the application.
1.897 - Usage example:
1.898 -
1.899 - uLong crc = crc32(0L, Z_NULL, 0);
1.900 -
1.901 - while (read_buffer(buffer, length) != EOF) {
1.902 - crc = crc32(crc, buffer, length);
1.903 - }
1.904 - if (crc != original_crc) error();
1.905 -*/
1.906 -
1.907 -
1.908 - /* various hacks, don't look :) */
1.909 -
1.910 -/* deflateInit and inflateInit are macros to allow checking the zlib version
1.911 - * and the compiler's view of z_stream:
1.912 - */
1.913 -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1.914 - const char *version, int stream_size));
1.915 -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1.916 - const char *version, int stream_size));
1.917 -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1.918 - int windowBits, int memLevel,
1.919 - int strategy, const char *version,
1.920 - int stream_size));
1.921 -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1.922 - const char *version, int stream_size));
1.923 -#define deflateInit(strm, level) \
1.924 - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
1.925 -#define inflateInit(strm) \
1.926 - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
1.927 -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1.928 - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1.929 - (strategy), ZLIB_VERSION, sizeof(z_stream))
1.930 -#define inflateInit2(strm, windowBits) \
1.931 - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1.932 -
1.933 -
1.934 -#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
1.935 - /**
1.936 - * @publishedAll
1.937 - * @released
1.938 - */
1.939 - struct internal_state {int dummy;}; /* hack for buggy compilers */
1.940 -#endif
1.941 -
1.942 -ZEXTERN const char * ZEXPORT zError OF((int err));
1.943 -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
1.944 -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
1.945 -
1.946 -#ifdef __cplusplus
1.947 -}
1.948 -#endif
1.949 -
1.950 -#endif /* _ZLIB_H */