/* zlib.h -- interface of the 'zlib' general purpose compression library $Log: zlibh.h,v $ Revision 1.5 2002/04/09 03:51:42 forrest@mibsoftware.com rights=#1 Added CHISEL subject. Updated LICENSE blocks. Revision 1.4 2002/03/18 19:27:32 forrest@mibsoftware.com rights=#1 update for 1.1.4 Revision 1.3 2002/02/10 03:17:22 forrest@mibsoftware.com rights=#1 Standardized chg log Revision 1.2 2002/01/30 16:08:11 forrest@mibsoftware.com rights=#1 Renamed some .h files Revision 1.1 2002/01/30 15:00:09 forrest@mibsoftware.com rights=#1 Renaming rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 librock_ACQUIRED: 2002-03-11 http://www.gzip.org/zlib/zlib-1.1.4.tar.gz http://www.gzip.org/zlib/ librock_ACQUIRED: 2001-10-23 ftp://ftp.uu.net/graphics/png/src/zlib-1.1.3.tar.gz http://www.gzip.org/zlib/ License text in librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ /* version 1.1.4, March 11th, 2002 Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Jean-loup Gailly Mark Adler jloup@gzip.org madler@alumni.caltech.edu The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). */ /* This file was modified in order to be part of librock, to ensure all #defines and declarations are librock_ prefixed. NOTE: This file should not be used when compiling the zlib implementation. The following replacements were made. _ZLIB_H librock__ZLIB_H OF librock_z_OF voidp librock_z_voidp voidpf librock_z_voidpf uInt librock_z_uInt uLong librock_z_uLong uLongf librock_z_uLongf Bytef librock_z_Bytef Byte librock_z_Byte ZEXTERN librock_ZEXTERN ZEXPORT librock_ZEXPORT ZEXPORTVA librock_ZEXPORTVA z_off_t librock_z_off_t ZLIB_VERSION librock_ZLIB_VERSION zlib librock_zlib alloc_func librock_z_alloc_func free_func librock_z_free_func internal_state librock_z_internal_state z_stream_s librock_z_stream_s z_stream librock_z_stream z_streamp librock_z_streamp Z_NO_FLUSH librock_Z_NO_FLUSH Z_PARTIAL_FLUSH librock_Z_PARTIAL_FLUSH Z_SYNC_FLUSH librock_Z_SYNC_FLUSH Z_FULL_FLUSH librock_Z_FULL_FLUSH Z_FINISH librock_Z_FINISH Z_OK librock_Z_OK Z_STREAM_END librock_Z_STREAM_END Z_NEED_DICT librock_Z_NEED_DICT Z_ERRNO librock_Z_ERRNO Z_STREAM_ERROR librock_Z_STREAM_ERROR Z_DATA_ERROR librock_Z_DATA_ERROR Z_MEM_ERROR librock_Z_MEM_ERROR Z_BUF_ERROR librock_Z_BUF_ERROR Z_VERSION_ERROR librock_Z_VERSION_ERROR Z_NO_COMPRESSION librock_Z_NO_COMPRESSION Z_BEST_SPEED librock_Z_BEST_SPEED Z_BEST_COMPRESSION librock_Z_BEST_COMPRESSION Z_DEFAULT_COMPRESSION librock_Z_DEFAULT_COMPRESSION Z_FILTERED librock_Z_FILTERED Z_HUFFMAN_ONLY librock_Z_HUFFMAN_ONLY Z_DEFAULT_STRATEGY librock_Z_DEFAULT_STRATEGY Z_BINARY librock_Z_BINARY Z_ASCII librock_Z_ASCII Z_UNKNOWN librock_Z_UNKNOWN Z_DEFLATED librock_Z_DEFLATED Z_NULL librock_Z_NULL zlib_version librock_zlib_version adler32 librock_z_adler32 crc32 librock_z_crc32 get_crc_table librock_z_get_crc_table zlibVersion librock_z_zlibVersion compress librock_z_compress compress2 librock_z_compress2 deflateInit librock_z_deflateInit deflateInit2 librock_z_deflateInit2 deflate librock_z_deflate deflateEnd librock_z_deflateEnd deflateSetDictionary librock_z_deflateSetDictionary deflateCopy librock_z_deflateCopy deflateReset librock_z_deflateReset deflateParams librock_z_deflateParams zError librock_z_zError uncompress librock_z_uncompress inflateInit librock_z_inflateInit inflateInit2 librock_z_inflateInit2 inflate librock_z_inflate inflateEnd librock_z_inflateEnd inflateSetDictionary librock_z_inflateSetDictionary inflateSync librock_z_inflateSync inflateReset librock_z_inflateReset inflateSyncPoint librock_z_inflateSyncPoint gzFile librock_z_gzFile gzopen librock_z_gzopen gzdopen librock_z_gzdopen gzsetparams librock_z_gzsetparams gzread librock_z_gzread gzwrite librock_z_gzwrite gzprintf librock_z_gzprintf gzputs librock_z_gzputs gzgets librock_z_gzgets gzputc librock_z_gzputc gzgetc librock_z_gzgetc gzflush librock_z_gzflush gzseek librock_z_gzseek gzrewind librock_z_gzrewind gztell librock_z_gztell gzeof librock_z_gzeof gzclose librock_z_gzclose gzerror librock_z_gzerror deflateInit_ librock_z_deflateInit_ inflateInit_ librock_z_inflateInit_ deflateInit2_ librock_z_deflateInit2_ inflateInit2_ librock_z_inflateInit2_ */ #ifndef librock__ZLIB_H #define librock__ZLIB_H #ifdef _ZUTIL_H #error This file should not be used to compile zlib implementation #endif #include #if 0 /* #include "zconf.h" */ /* Not included because it puts many things in the #define and link namespace which are not librock_ prefixed. zconf.h is used when compiling the implementation, but we #define everything we need from zconf.h in this file. */ #endif #define librock_z_OF(args) args typedef void *librock_z_voidp; #define librock_z_voidpf void librock_PTR * #define librock_z_uInt unsigned int #define librock_z_uLong unsigned long #define librock_z_uLongf unsigned long librock_PTR #define librock_z_Bytef unsigned char librock_PTR #define librock_z_Byte unsigned char #define librock_ZEXTERN #define librock_ZEXPORT #define librock_ZEXPORTVA #define librock_z_off_t librock_OFFSET_T #ifdef __cplusplus extern "C" { #endif #define librock_ZLIB_VERSION "1.1.4" #ifdef librock_MANUAL_zlib librock_CHISEL subject /data/compress/ /* librock_zlib - standard zlib compression and decompression, with librock_ name prefix */ /**/ #include #include /* This is version 1.1.4 of zlib, Jean-loup Gailly and Mark Adler's very popular compression library, modified so that the interface and header file use the @librock_ prefix exclusively in all defines and external names and macro definitions. The librock license awareness system is also present in this implementation. The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output (providing more output space) before each call. [details] The opposite action, called inflation, is similar. [details] The library also supports a stdio-like interface to gzip (.gz) files (reading, writing, seeking, rewinding, puts, gets, printf, et al.) [details] The interface to checksum functions is also exposed. [details] /* These functions are well-behaved in multi-threaded environments. The zlib functions do not install any signal handler, and return error codes instead of exiting or throwing exceptions. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. */ /* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ #endif /* MANUAL */ typedef librock_z_voidpf (*librock_z_alloc_func) librock_z_OF((librock_z_voidpf opaque, librock_z_uInt items, librock_z_uInt size)); typedef void (*librock_z_free_func) librock_z_OF((librock_z_voidpf opaque, librock_z_voidpf address)); struct librock_z_internal_state; typedef struct librock_z_stream_s { librock_z_Bytef *next_in; /* next input byte */ librock_z_uInt avail_in; /* number of bytes available at next_in */ librock_z_uLong total_in; /* total nb of input bytes read so librock_PTR */ librock_z_Bytef *next_out; /* next output byte should be put there */ librock_z_uInt avail_out; /* remaining free space at next_out */ librock_z_uLong total_out; /* total nb of bytes output so librock_PTR */ char *msg; /* last error message, NULL if no error */ struct librock_z_internal_state librock_PTR *state; /* not visible by applications */ librock_z_alloc_func zalloc; /* used to allocate the internal state */ librock_z_free_func zfree; /* used to free the internal state */ librock_z_voidpf opaque; /* private data object passed to zalloc and zfree */ int data_type; /* best guess about the data type: ascii or binary */ librock_z_uLong adler; /* adler32 value of the uncompressed data */ librock_z_uLong reserved; /* reserved for future use */ } librock_z_stream; typedef librock_z_stream librock_PTR *librock_z_streamp; /* The application must update next_in and avail_in when avail_in has dropped to zero. It must update next_out and avail_out when avail_out has dropped to zero. The application must initialize zalloc, zfree and opaque before calling the init function. All other fields are set by the compression library and must not be updated by the application. The opaque value provided by the application will be passed as the first parameter for calls of zalloc and zfree. This can be useful for custom memory management. The compression library attaches no meaning to the opaque value. zalloc must return Z_NULL if there is not enough memory for the object. If zlib is used in a multi-threaded application, zalloc and zfree must be thread safe. On 16-bit systems, the functions zalloc and zfree must be able to allocate exactly 65536 bytes, but will not be required to allocate more than this if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers returned by zalloc for objects of exactly 65536 bytes *must* have their offset normalized to zero. The default allocation function provided by the zlib functions ensures this (see zutil.c). To reduce memory requirements and avoid any allocation of 64K objects, at the expense of compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). The fields total_in and total_out can be used for statistics or progress reports. After compression, total_in holds the total size of the uncompressed data and may be saved for use in the decompressor (particularly if the decompressor wants to decompress everything in a single step). */ /* constants */ #define librock_Z_NO_FLUSH 0 #define librock_Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ #define librock_Z_SYNC_FLUSH 2 #define librock_Z_FULL_FLUSH 3 #define librock_Z_FINISH 4 /* Allowed flush values; see deflate() below for details */ #define librock_Z_OK 0 #define librock_Z_STREAM_END 1 #define librock_Z_NEED_DICT 2 #define librock_Z_ERRNO (-1) #define librock_Z_STREAM_ERROR (-2) #define librock_Z_DATA_ERROR (-3) #define librock_Z_MEM_ERROR (-4) #define librock_Z_BUF_ERROR (-5) #define librock_Z_VERSION_ERROR (-6) /* Return codes for the compression/decompression functions. Negative * values are errors, positive values are used for special but normal events. */ #define librock_Z_NO_COMPRESSION 0 #define librock_Z_BEST_SPEED 1 #define librock_Z_BEST_COMPRESSION 9 #define librock_Z_DEFAULT_COMPRESSION (-1) /* compression levels */ #define librock_Z_FILTERED 1 #define librock_Z_HUFFMAN_ONLY 2 #define librock_Z_DEFAULT_STRATEGY 0 /* compression strategy; see deflateInit2() below for details */ #define librock_Z_BINARY 0 #define librock_Z_ASCII 1 #define librock_Z_UNKNOWN 2 /* Possible values of the data_type field */ #define librock_Z_DEFLATED 8 /* The deflate compression method (the only one supported in this version) */ #define librock_Z_NULL 0 /* for initializing zalloc, zfree, opaque */ #define librock_zlib_version zlibVersion() /* for compatibility with versions < 1.0.2 */ /**************************************************************/ #ifdef librock_MANUAL_zlib_checksum librock_CHISEL subject /data/compress/ librock_CHISEL subject /data/integrity/ librock_CHISEL _bodysrc acquired/zlib/adler32.c librock_z_adler32 librock_CHISEL _bodysrc acquired/zlib/zcrc32.c librock_z_crc32 /* librock_z_adler32 - Checksum function from zlib librock_z_crc32 - Checksum function from zlib */ /*
These functions do not perform compress/uncompress, but they are used for integrity checks. */ #include #include librock_z_uLong librock_z_adler32(librock_z_uLong adler, const librock_z_Bytef *buf, librock_z_uInt len); /*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. If buf is NULL, this function returns the required initial value for the checksum. An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much faster. Usage example: */ librock_z_uLong adler = librock_z_adler32(0L, librock_z_Z_NULL, 0); while (read_buffer(buffer, length) != EOF) { adler = librock_z_adler32(adler, buffer, length); } if (adler != original_adler) error(); /*
*/ librock_z_uLong librock_z_crc32(librock_z_uLong crc, const librock_z_Bytef *buf, librock_z_uInt len); /*
Update a running crc with the bytes @buf[0..len-1] and return the updated crc. If @buf is NULL, this function returns the required initial value for the crc. Pre- and post-conditioning (one's complement) is performed within this function so it shouldn't be done by the application. This means that the required initial value is 0, but the code below has the recommended initialization. Note that librock already includes a function librock_CRC32, with a very similar implementation. Since the API is slightly different, they are not replacement compatible. Usage example: */ librock_z_uLong crc = librock_z_crc32(0L, librock_Z_NULL, 0); while (read_buffer(buffer, length) != EOF) { crc = librock_z_crc32(crc, buffer, length); } if (crc != original_crc) error(); /*
*/ /* //No external calls */ /* These functions are well-behaved in multi-threaded environments. The zlib functions do not install any signal handler, and return error codes instead of exiting or throwing exceptions. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. */ /* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ #endif /* MANUAL */ /**************************************************************/ /* basic functions */ /**************************************************************/ #ifdef librock_MANUAL_zlib_deflate librock_CHISEL subject /data/compress/ /* librock_zlib_deflate - functions for data compression using zlib librock_z_zlibVersion - check for compatible zlib version librock_z_compress - compress source buffer to destination buffer using default options librock_z_compress2 - compress source buffer to destination buffer at specified level using default options librock_z_deflateInit - initialize zlib compression stream librock_z_deflateInit2 - initialize zlib compression stream, with more options. librock_z_deflate - compress as much data as possible from the zlib stream, possibly flush. librock_z_deflateEnd - free allocations used by the zlib compression stream. librock_z_deflateSetDictionary - initialize compression dictionary for a stream. librock_z_deflateCopy - duplicate a compression stream, including internal state. librock_z_deflateReset - Re-initialize zlib compression stream. librock_z_deflateParams - Dynamically update compression strategy for a stream. librock_z_zError - Convert zlib error code to string. */ /**/ /*
*/ #include #include const char * librock_z_zlibVersion (void); /*
The application can compare zlibVersion and librock_ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check is automatically made by deflateInit and inflateInit.
*/ int librock_z_compress (librock_z_Bytef *dest, librock_z_uLongf *destLen, librock_z_Bytef *source, librock_z_uLong sourceLen); /*
Compresses the source buffer into the destination buffer. @sourceLen is the byte length of the source buffer. Upon entry, @destLen is the total size of the destination buffer, which must be at least 0.1% larger than @sourceLen plus 12 bytes. Upon exit, @destLen is the actual size of the compressed buffer. This function can be used to compress a whole file at once if the input file is mmap'ed. compress returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_BUF_ERROR if there was not enough room in the output buffer. This is a utility function implemented by calling the basic stream-oriented librock_z_deflate* functions described below. To simplify the interface, some default options are assumed (compression level and memory usage, standard memory allocation functions). The source code of these utility functions can easily be modified if you need special options. Typical use: */ int err; const char *data; /* Data to compress */ librock_z_uLong len; /* Length of data to compress */ librock_z_Byte *compr, *uncompr; librock_z_uLong comprLen, uncomprLen; /* Set up compr, comprLen */ err = librock_z_compress(compr, &comprLen, (const librock_z_Bytef*)data, len); if (err != librock_Z_OK) { error handling here; } . . . err = librock_z_uncompress(uncompr, &uncomprLen, compr, comprLen); if (err != librock_Z_OK) { error handling here; } /*
*/ int librock_z_compress2 (librock_z_Bytef *dest, librock_z_uLongf *destLen, const librock_z_Bytef *source, librock_z_uLong sourceLen, int level); /*
Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in @librock_z_deflateInit(). @sourceLen is the byte length of the source buffer. Upon entry, @destLen is the total size of the destination buffer, which must be at least 0.1% larger than @sourceLen plus 12 bytes. Upon exit, @destLen is the actual size of the compressed buffer. compress2 returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_BUF_ERROR if there was not enough room in the output buffer, @librock_Z_STREAM_ERROR if the level parameter is invalid. This is a utility function implemented by calling the basic stream-oriented librock_z_deflate* functions described below. To simplify the interface, some default options are assumed (compression level and memory usage, standard memory allocation functions). The source code of these utility functions can easily be modified if you need special options.
*/ int librock_z_deflateInit (struct librock_z_stream_s *strm, int level); /*
*/ /* Initializes the internal stream state for compression. The fields @strm->zalloc , @strm->zfree and @strm->opaque must be initialized before by the caller. If @strm->zalloc and @strm->zfree are set to @librock_Z_NULL, @librock_z_deflateInit() updates them to use default allocation functions, @malloc() and @free() The opaque value provided by the application will be passed as the first parameter for calls of custom zalloc and zfree. This can be useful for custom memory management. The compression library attaches no meaning to the opaque value. A custom @strm->zalloc must return @librock_Z_NULL if there is not enough memory for the object. If zlib is used in a multi-threaded application, the allocation functions must be thread safe. The application must update @strm->next_in and @strm->avail_in when @strm->avail_in has dropped to zero. It must update @strm->next_out and @strm->avail_out when @strm->avail_out has dropped to zero. All other fields are set by the compression library and must not be updated by the application. The fields @strm->total_in and @strm->total_out can be used for statistics or progress reports. After compression, @strm->total_in holds the total size of the uncompressed data and may be saved for use in the decompressor (particularly if the decompressor wants to decompress everything in a single step). The complete fields of @struct @librock_z_stream_s are: */ struct librock_z_stream_s { librock_z_Bytef *next_in; /* next input byte */ librock_z_uInt avail_in; /* number of bytes available at next_in */ librock_z_uLong total_in; /* total nb of input bytes read so librock_PTR */ librock_z_Bytef *next_out; /* next output byte should be put there */ librock_z_uInt avail_out; /* remaining free space at next_out */ librock_z_uLong total_out; /* total nb of bytes output so librock_PTR */ char *msg; /* last error message, NULL if no error */ struct librock_z_internal_state librock_PTR *state; /* not visible by applications */ librock_z_alloc_func zalloc; /* used to allocate the internal state */ librock_z_free_func zfree; /* used to free the internal state */ librock_z_voidpf opaque; /* private data object passed to zalloc and zfree */ int data_type; /* best guess about the data type: ascii or binary */ librock_z_uLong adler; /* adler32 value of the uncompressed data */ librock_z_uLong reserved; /* reserved for future use */ }; /* The @level parameter is the compression level which must be @librock_Z_DEFAULT_COMPRESSION , @librock_Z_BEST_SPEED , @librock_Z_NO_COMPRESSION, @librock_Z_BEST_COMPRESSION , or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time). @librock_Z_DEFAULT_COMPRESSION requests a default compromise between speed and compression (currently equivalent to level 6). @librock_z_deflateInit returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_STREAM_ERROR if level is not a valid compression level, @librock_Z_VERSION_ERROR if the zlib library version (@librock_zlib_version() ) is incompatible with the version assumed by the caller (@librock_ZLIB_VERSION). @strm->msg is set to null if there is no error message. @librock_z_deflateInit() does not perform any compression: this will be done by @librock_z_deflate(). @librock_z_deflateInit() is implemented as a macro which expands to be a call to int librock_z_deflateInit_ (librock_z_streamp strm, int level, const char *version, int stream_size);
*/ int librock_z_deflateInit2 (librock_z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy); /*
This is another version of @librock_z_deflateInit with more compression options. The fields @strm->next_in , @strm->zalloc , @strm->zfree and @strm->opaque must be initialized before by the caller. The method parameter is the compression method. It must be @librock_Z_DEFLATED in this version of the library. The @windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage. The default value is 15 if deflateInit is used instead. The @memLevel parameter specifies how much memory should be allocated for the internal compression state. memLevel=1 uses minimum memory but is slow and reduces compression ratio; memLevel=9 uses maximum memory for optimal speed. The default value is 8. See zconf.h for total memory usage as a function of windowBits and memLevel. The @strategy parameter is used to tune the compression algorithm. Use the value @librock_Z_DEFAULT_STRATEGY for normal data, @librock_Z_FILTERED for data produced by a filter (or predictor), or @librock_Z_HUFFMAN_ONLY to force Huffman encoding only (no string match). Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. The effect of @librock_Z_FILTERED is to force more Huffman coding and less string matching; it is somewhat intermediate between @librock_Z_DEFAULT and @librock_Z_HUFFMAN_ONLY. The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately. @librock_z_deflateInit2() returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_STREAM_ERROR if a parameter is invalid (such as an invalid method). @strm->msg is set to null if there is no error message. @librock_z_deflateInit2 does not perform any compression: this will be done by @librock_z_deflate(). This is implemented as a macro which calls int librock_z_deflateInit2_ (librock_z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size);
*/ int librock_z_deflate (librock_z_streamp strm, int flush); /*
@librock_z_deflate() compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush. The detailed semantics are as follows. @librock_z_deflate() performs one or both of the following actions:
  • Compress more input starting at @strm->next_in and update @strm->next_in and @strm->avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), @strm->next_in and @strm->avail_in are updated and processing will resume at this point for the next call of @librock_z_deflate() .
  • Provide more output starting at @strm->next_out and update @strm->next_out and @strm->avail_out accordingly. This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.
Before the call of @librock_z_deflate() , the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating @strm->avail_in or @strm->avail_out accordingly; @strm->avail_out should never be zero before the call. The application can consume the compressed output when it wants, for example when the output buffer is full (@strm->avail_out == 0), or after each call of @librock_z_deflate() . If @librock_z_deflate() returns @librock_Z_OK and with zero @strm->avail_out, it must be called again after making room in the output buffer because there might be more output pending. If the parameter @flush is set to @librock_Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. (In particular @strm->avail_in is zero after the call if enough output space has been provided before the call.) Flushing may degrade compression for some compression algorithms and so it should be used only when necessary. If flush is set to @librock_Z_FULL_FLUSH, all output is flushed as with @librock_Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using @librock_Z_FULL_FLUSH too often can seriously degrade the compression. If @librock_z_deflate() returns with @strm->avail_out == 0, this function must be called again with the same value of the flush parameter and more output space (updated @strm->avail_out), until the flush is complete (@librock_z_deflate returns with non-zero @strm->avail_out). If the parameter @flush is set to @librock_Z_FINISH, pending input is processed, pending output is flushed and librock_z_deflate returns with @librock_Z_STREAM_END (if there was enough output space) and @librock_Z_OK (if this function must be called again with @librock_Z_FINISH and more output space (updated @strm->avail_out) but no more input data) The caller should repeat until it returns with @librock_Z_STREAM_END or an error. After librock_z_deflate has returned @librock_Z_STREAM_END, the only possible operations on the stream are @librock_z_deflateReset or @librock_z_deflateEnd. @librock_Z_FINISH can be used immediately after @librock_z_deflateInit() if all the compression is to be done in a single step. In this case, @strm->avail_out must be at least 0.1% larger than avail_in plus 12 bytes. If librock_z_deflate does not return @librock_Z_STREAM_END, then it must be called again as described above. @librock_z_deflate() sets strm->adler to the librock_z_adler32 checksum of all input read so far (that is, strm->total_in bytes). @librock_z_deflate() may update @strm->data_type if it can make a good guess about the input data type (@librock_Z_ASCII or @librock_Z_BINARY). In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner. @librock_z_deflate() returns @librock_Z_OK if some progress has been made (more input processed or more output produced), @librock_Z_STREAM_END if all input has been consumed and all output has been produced (only when flush is set to @librock_Z_FINISH), @librock_Z_STREAM_ERROR if the stream state was inconsistent (for example if next_in or next_out was @NULL ), @librock_Z_BUF_ERROR if no progress is possible (for example @strm->avail_in or @strm->avail_out was zero).
*/ int librock_z_deflateEnd (librock_z_streamp strm); /*
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output. @librock_z_deflateEnd returns @librock_Z_OK if success, @librock_Z_STREAM_ERROR if the stream state was inconsistent, @librock_Z_DATA_ERROR if the stream was freed prematurely (some input or output was discarded). In the error case, @strm->msg may be set but then points to a static string (which must not be deallocated).
*/ /* The following functions are needed only in some special applications.
*/ int librock_z_deflateSetDictionary (librock_z_streamp strm, const librock_z_Bytef *dictionary, librock_z_uInt dictLength); /*
Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called immediately after @librock_z_deflateInit() , @librock_z_deflateInit2 or @librock_z_deflateReset() , before any call of @librock_z_deflate. The compressor and decompressor must use exactly the same dictionary (see @librock_z_inflateSetDictionary() ). The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary. Depending on the size of the compression data structures selected by @librock_z_deflateInit() or @librock_z_deflateInit2() , a part of the dictionary may in effect be discarded, for example if the dictionary is larger than the window size in @librock_z_deflate or @deflate2. Thus the strings most likely to be useful should be put at the end of the dictionary, not at the front. Upon return of this function, @strm->adler is set to the Adler32 value of the dictionary; the decompressor may later use this value to determine which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.) @librock_z_deflateSetDictionary() returns @librock_Z_OK if success, or @librock_Z_STREAM_ERROR if a parameter is invalid (such as @NULL dictionary) or the stream state is inconsistent (for example if @librock_z_deflate() has already been called for this stream or if the compression method is @bsort ). @librock_z_deflateSetDictionary() does not perform any compression: this will be done by @librock_z_deflate() .
*/ int librock_z_deflateCopy (librock_z_streamp dest, librock_z_streamp source); /*
Sets the destination stream as a complete copy of the source stream. This function can be useful when several compression strategies will be tried, for example when there are several ways of pre-processing the input data with a filter. The streams that will be discarded should then be freed by calling @librock_z_deflateEnd(). Note that @librock_z_deflateCopy duplicates the internal compression state which can be quite large, so this strategy is slow and can consume lots of memory. @librock_z_deflateCopy() returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_STREAM_ERROR if the source stream state was inconsistent (such as @strm->zalloc being @NULL). @strm->msg is left unchanged in both source and destination.
*/ int librock_z_deflateReset (librock_z_streamp strm); /*
This function is equivalent to @librock_z_deflateEnd() followed by @librock_z_deflateInit() , but does not free and reallocate all the internal compression state. The stream will keep the same compression level and any other attributes that may have been set by @librock_z_deflateInit2() . @librock_z_deflateReset() returns @librock_Z_OK if success, or @librock_Z_STREAM_ERROR if the source stream state was inconsistent (such as @strm->zalloc or state being @NULL).
*/ int librock_z_deflateParams (librock_z_streamp strm, int level, int strategy); /*
Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in @librock_z_deflateInit2() . This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level (and may be flushed); the new level will take effect only at the next call of @librock_z_deflate() . Before the call of @librock_z_deflateParams() , the stream state must be set as for a call of @librock_z_deflate() , since the currently available input may have to be compressed and flushed. In particular, @strm->avail_out must be non-zero. @librock_z_deflateParams() returns @librock_Z_OK if success, @librock_Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, @librock_Z_BUF_ERROR if @strm->avail_out was zero.
*/ const char * librock_z_zError (int err); /*
allow conversion of error code to string for @librock_z_compress() and @librock_z_uncompress(). For most other functions @strm->msg is already set.
*/ /* memcpy memset calloc free librock_CHISEL _bodysrc ./acquired/zlib/adler32.c librock_CHISEL _bodysrc ./acquired/zlib/compress.c librock_CHISEL _bodysrc ./acquired/zlib/deflate.c librock_CHISEL _bodysrc ./acquired/zlib/deflate.h librock_CHISEL _bodysrc ./acquired/zlib/trees.h librock_CHISEL _bodysrc ./acquired/zlib/zconf.h librock_CHISEL _bodysrc ./acquired/zlib/zcrc32.c librock_CHISEL _bodysrc ./acquired/zlib/zlib.h librock_CHISEL _bodysrc ./acquired/zlib/ztrees.c librock_CHISEL _bodysrc ./acquired/zlib/zutil.c librock_CHISEL _bodysrc ./acquired/zlib/zutil.h librock_CHISEL _bodysrc ./librock/zlibh.h */ /* These functions are well-behaved in multi-threaded environments. The zlib functions do not install any signal handler, and return error codes instead of exiting or throwing exceptions. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. */ /* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ #endif /* MANUAL */ /**************************************************************/ librock_ZEXTERN const char * librock_ZEXPORT librock_z_zlibVersion librock_z_OF((void)); /**************************************************************/ #ifdef librock_MANUAL_zlib_inflate librock_CHISEL subject /data/compress/ /* librock_zlib_inflate - functions for data uncompression from zlib librock_z_zlibVersion - check for compatible zlib version librock_z_uncompress - uncompress source buffer to destination buffer using default options librock_z_inflateInit - initialize zlib decompression stream librock_z_inflateInit2 - initialize zlib decompression stream, with windowBits limit. librock_z_inflate - decompress as much data as possible from the zlib stream, possibly flush. librock_z_inflateEnd - free allocations used by the zlib decompression stream. librock_z_zError - Convert zlib error code to string. librock_z_inflateSetDictionary - initialize decompression dictionary for a stream. librock_z_inflateSync - skip invalid data until a full flush point is found. librock_z_inflateSyncPoint - Test if stream is at the end of a block. */ /**/ #include #include /*
*/ const char * librock_z_zlibVersion (void); /*
The application can compare zlibVersion and librock_ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check is automatically made by deflateInit and inflateInit.
*/ int librock_z_uncompress (librock_z_Bytef *dest, librock_z_uLongf *destLen, const librock_z_Bytef *source, librock_z_uLong sourceLen); /*
Decompresses the source buffer into the destination buffer. @sourceLen is the byte length of the source buffer. Upon entry, @destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, @destLen is the actual size of the compressed buffer. This function can be used to decompress a whole file at once if the input file is mmap'ed. @librock_z_uncompress() returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_BUF_ERROR if there was not enough room in the output buffer, or @librock_Z_DATA_ERROR if the input data was corrupted. This is a utility function implemented by calling the basic stream-oriented librock_z_inflate* functions described below. To simplify the interface, some default options are assumed (compression level and memory usage, standard memory allocation functions). The source code of these utility functions can easily be modified if you need special options.
*/ int librock_z_inflateInit (struct librock_z_stream *strm); /*
Initializes the internal stream state for decompression. The fields @strm->zalloc , @strm->zfree and @strm->opaque must be initialized before by the caller. If @strm->zalloc and @strm->zfree are set to @librock_Z_NULL, librock_z_deflateInit updates them to use default allocation functions, @malloc() and @free() The @strm->opaque value provided by the application will be passed as the first parameter for calls of custom zalloc and zfree. This can be useful for custom memory management. The zlib functions attach no meaning to the opaque value. A custom @strm->zalloc must return @librock_Z_NULL if there is not enough memory for the object. If zlib is used in a multi-threaded application, the allocation functions must be thread safe. @strm->next_in , @strm->avail_in, must be initialized before by the caller. If @strm->next_in is not @librock_Z_NULL and @strm->avail_in is large enough (the exact value depends on the compression method), @librock_z_inflateInit determines the compression method from the zlib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of @librock_z_inflate() . The application must update @strm->next_in and @strm->avail_in when @strm->avail_in has dropped to zero. It must update @strm->next_out and @strm->avail_out when strm->avail_out has dropped to zero. All other fields are set by the implementation and must not be updated by the application. The fields @strm->total_in and @strm->total_out can be used for statistics or progress reports. The complete fields of @struct @librock_z_stream_s are: */ struct librock_z_stream_s { librock_z_Bytef *next_in; /* next input byte */ librock_z_uInt avail_in; /* number of bytes available at next_in */ librock_z_uLong total_in; /* total nb of input bytes read so librock_PTR */ librock_z_Bytef *next_out; /* next output byte should be put there */ librock_z_uInt avail_out; /* remaining free space at next_out */ librock_z_uLong total_out; /* total nb of bytes output so librock_PTR */ char *msg; /* last error message, NULL if no error */ struct librock_z_internal_state librock_PTR *state; /* not visible by applications */ librock_z_alloc_func zalloc; /* used to allocate the internal state */ librock_z_free_func zfree; /* used to free the internal state */ librock_z_voidpf opaque; /* private data object passed to zalloc and zfree */ int data_type; /* best guess about the data type: ascii or binary */ librock_z_uLong adler; /* adler32 value of the uncompressed data */ librock_z_uLong reserved; /* reserved for future use */ }; /* @inflateInit() returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_VERSION_ERROR if the zlib library version is incompatible with the version assumed by the caller. @strm->msg is set to null if there is no error message. @librock_z_inflateInit does not perform any decompression apart from reading the zlib header if present: this will be done by @librock_z_inflate() . (So @strm->next_in and @strm->avail_in may be modified, but @strm->next_out and @strm->avail_out are unchanged.) @librock_z_inflateInit() is actually a macro which expands to int librock_z_inflateInit_ (librock_z_streamp strm, const char *version, int stream_size);
*/ int librock_z_inflateInit2 (librock_z_streamp strm, int windowBits); /*
This is another version of @librock_z_inflateInit with an extra parameter. The fields @strm->next_in , @strm->avail_in , @strm->zalloc , @strm->zfree and @strm->opaque must be initialized before by the caller. The @windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. The default value is 15 if @librock_z_inflateInit is used instead. If a compressed stream with a larger window size is given as input, @librock_z_inflate() will return with the error code @librock_Z_DATA_ERROR instead of trying to allocate a larger window. @librock_z_inflateInit2() returns @librock_Z_OK if success, @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_STREAM_ERROR if a parameter is invalid (such as a negative memLevel). msg is set to null if there is no error message. @librock_z_inflateInit2 does not perform any decompression apart from reading the @librock_zlib header if present: this will be done by @librock_z_inflate(). (So @strm->next_in and @strm->avail_in may be modified, but @strm->next_out and @strm->avail_out are unchanged.) @librock_z_inflateInit2 is actually a macro which expands to int librock_z_inflateInit2_ (librock_z_streamp strm, int windowBits, const char *version, int stream_size);
*/ int librock_z_inflate (librock_z_streamp strm, int flush); /*
@librock_z_inflate() decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush. The detailed semantics are as follows. @librock_z_inflate() performs one or both of the following actions:
  • Decompress more input starting at @strm->next_in and update @strm->next_in and @strm->avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), @strm->next_in is updated and processing will resume at this point for the next call of @librock_z_inflate().
  • Provide more output starting at @strm->next_out and update @strm->next_out and @strm->avail_out accordingly. @librock_z_inflate() provides as much output as possible, until there is no more input data or no more space in the output buffer (see below about the @flush parameter).
Before the call of @librock_z_inflate() , the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the strm->next_* and strm->avail_* values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (@strm->avail_out == 0), or after each call of @librock_z_inflate(). If @librock_z_inflate returns @librock_Z_OK and with zero @strm->avail_out, it must be called again after making room in the output buffer because there might be more output pending. If the parameter flush is set to @librock_Z_SYNC_FLUSH, @librock_z_inflate flushes as much output as possible to the output buffer. The flushing behavior of @librock_z_inflate is not specified for values of the flush parameter other than @librock_Z_SYNC_FLUSH and @librock_Z_FINISH, but the current implementation actually flushes as much output as possible anyway. @librock_z_inflate() should normally be called until it returns @librock_Z_STREAM_END or an error. However if all decompression is to be performed in a single step (a single call of @librock_z_inflate), the parameter flush should be set to @librock_Z_FINISH . In this case all pending input is processed and all pending output is flushed; @strm->avail_out must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been saved by the compressor for this purpose.) The next operation on this stream must be @librock_z_inflateEnd to deallocate the decompression state. The use of @librock_Z_FINISH is never required, but can be used to inform @librock_z_inflate that a faster routine may be used for the single @librock_z_inflate() call. If a preset dictionary is needed at this point (see @librock_z_inflateSetDictionary below), @librock_z_inflate sets @strm->adler to the @librock_z_adler32 checksum of the dictionary chosen by the compressor and returns @librock_Z_NEED_DICT; otherwise it sets @strm->adler to the @librock_z_adler32 checksum of all output produced so far (that is, total_out bytes) and returns @librock_Z_OK, @librock_Z_STREAM_END or an error code as described below. At the end of the stream, @librock_z_inflate() checks that its computed @librock_z_adler32 checksum is equal to that saved by the compressor and returns @librock_Z_STREAM_END only if the checksum is correct. @librock_z_inflate() returns @librock_Z_OK if some progress has been made (more input processed or more output produced), @librock_Z_STREAM_END if the end of the compressed data has been reached and all uncompressed output has been produced, @librock_Z_NEED_DICT if a preset dictionary is needed at this point, @librock_Z_DATA_ERROR if the input data was corrupted (input stream not conforming to the @librock_zlib format or incorrect @librock_z_adler32 checksum), @librock_Z_STREAM_ERROR if the stream structure was inconsistent (for example if @strm->next_in or @strm->next_out was NULL), @librock_Z_MEM_ERROR if there was not enough memory, @librock_Z_BUF_ERROR if no progress is possible or if there was not enough room in the output buffer when @librock_Z_FINISH is used. In the @librock_Z_DATA_ERROR case, the application may then call @librock_z_inflateSync() to look for a good compression block.
*/ int librock_z_inflateEnd(librock_z_streamp strm); /*
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output. @librock_z_inflateEnd() returns @librock_Z_OK if success, @librock_Z_STREAM_ERROR if the stream state was inconsistent. In the error case, @strm->msg may be set but then points to a static string (which must not be deallocated).
*/ const char * librock_z_zError(int err); /*
allow conversion of error code to string for @librock_z_compress() and @librock_z_uncompress(). For most other functions @strm->msg is already set.
*/ /* */ /* The following functions are needed only in some special applications.
*/ int librock_z_inflateSetDictionary (librock_z_streamp strm, const librock_z_Bytef *dictionary, librock_z_uInt dictLength); /*
Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of @librock_z_inflate if this call returned @librock_Z_NEED_DICT. The dictionary chosen by the compressor can be determined from the Adler32 value returned by this call of @librock_z_inflate. The compressor and decompressor must use exactly the same dictionary (see @librock_z_deflateSetDictionary). @librock_z_inflateSetDictionary returns @librock_Z_OK if success, @librock_Z_STREAM_ERROR if a parameter is invalid (such as NULL dictionary) or the stream state is inconsistent, @librock_Z_DATA_ERROR if the given dictionary doesn't match the expected one (incorrect Adler32 value). @librock_z_inflateSetDictionary does not perform any decompression: this will be done by subsequent calls of @librock_z_inflate() .
*/ int librock_z_inflateSync (librock_z_streamp strm); /*
Skips invalid compressed data until a full flush point (see above the description of @librock_z_deflate with @librock_Z_FULL_FLUSH) can be found, or until all available input is skipped. No output is provided. @librock_z_inflateSync() returns @librock_Z_OK if a full flush point has been found, @librock_Z_BUF_ERROR if no more input was provided, @librock_Z_DATA_ERROR if no flush point has been found, or @librock_Z_STREAM_ERROR if the stream structure was inconsistent. In the success case, the application may save the current current value of @strm->total_in which indicates where valid compressed data was found. In the error case, the application may repeatedly call @librock_z_inflateSync, providing more input each time, until success or end of the input data.
*/ int librock_z_inflateReset (librock_z_streamp strm); /*
This function is equivalent to @librock_z_inflateEnd followed by @librock_z_inflateInit, but does not free and reallocate all the internal decompression state. The stream will keep attributes that may have been set by @librock_z_inflateInit2. @librock_z_inflateReset returns @librock_Z_OK if success, or @librock_Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being NULL).
*/ int librock_z_inflateSyncPoint (librock_z_streamp z); /*
Returns true if @librock_z_inflate is currently at the end of a block generated by @librock_Z_SYNC_FLUSH or @librock_Z_FULL_FLUSH. Typical Use: This function is used by one PPP implementation to provide an additional safety check. PPP uses @librock_Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored block. When decompressing, PPP checks that at the end of input packet, @librock_z_inflate is waiting for these length bytes. */ /*
*/ /* memcpy memset calloc free librock_CHISEL _bodysrc ./acquired/zlib/adler32.c librock_CHISEL _bodysrc ./acquired/zlib/zcrc32.c librock_CHISEL _bodysrc ./acquired/zlib/infblock.c librock_CHISEL _bodysrc ./acquired/zlib/infblock.h librock_CHISEL _bodysrc ./acquired/zlib/infcodes.c librock_CHISEL _bodysrc ./acquired/zlib/infcodes.h librock_CHISEL _bodysrc ./acquired/zlib/inffast.c librock_CHISEL _bodysrc ./acquired/zlib/inffast.h librock_CHISEL _bodysrc ./acquired/zlib/inffixed.h librock_CHISEL _bodysrc ./acquired/zlib/inflate.c librock_CHISEL _bodysrc ./acquired/zlib/inftrees.c librock_CHISEL _bodysrc ./acquired/zlib/inftrees.h librock_CHISEL _bodysrc ./acquired/zlib/infutil.c librock_CHISEL _bodysrc ./acquired/zlib/infutil.h librock_CHISEL _bodysrc ./acquired/zlib/trees.h librock_CHISEL _bodysrc ./acquired/zlib/zconf.h librock_CHISEL _bodysrc ./acquired/zlib/zlib.h librock_CHISEL _bodysrc ./acquired/zlib/ztrees.c librock_CHISEL _bodysrc ./acquired/zlib/zutil.c librock_CHISEL _bodysrc ./acquired/zlib/zutil.h librock_CHISEL _bodysrc ./librock/zlibh.h */ /* These functions are well-behaved in multi-threaded environments. The zlib functions do not install any signal handler, and return error codes instead of exiting or throwing exceptions. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. */ /* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ /**************************************************************/ #endif /* MANUAL */ /**************************************************************/ #ifdef librock_MANUAL_zlib_gzio librock_CHISEL subject /data/compress/ /* librock_zlib_gzio - transparent gzip file reading and writing librock_z_gzopen - Open a .gz file for reading or writing. librock_z_gzdopen - associates a file descriptor. librock_z_gzparams - dynamically update compression parameters. librock_z_gzread - uncompress bytes from the file. librock_z_gzwrite - compress bytes into the file. librock_z_gzprintf - as with fprintf, but write compressed. librock_z_gzputs - compress a string up to a NUL into the file. librock_z_gzgets - uncompress a string from file. librock_z_gzputc - write a character to compressed file. librock_z_gzgets - uncompress a character from file. librock_z_gzflush - flush all pending output to the compressed file. librock_z_gzseek - set position for next read or write of compressed file. librock_z_gzrewind - rewind a compressed file. librock_z_gztell - report position for next read or write. librock_z_gzeof - report EOF previously detected. librock_z_gzclose - flush output, deallocate internal state, close file. librock_z_gzerror - return most recent error message during operation on compressed file. */ /**/ /*
*/ #include #include librock_z_gzFile librock_z_gzopen (const char *path, const char *mode); /*
Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen ("rb" or "wb") but can also include a compression level ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman only compression as in "wb1h". (See the description of librock_z_deflateInit2 for more information about the strategy parameter.) @librock_z_gzopen can be used to read a file which is not in gzip format; in this case @librock_z_gzread will directly read from the file without decompression. @librock_z_gzopen returns NULL if the file could not be opened or if there was insufficient memory to allocate the (de)compression state; @errno can be checked to distinguish the two cases (if errno is zero, the librock_zlib error is @librock_Z_MEM_ERROR).
*/ librock_z_gzFile librock_z_gzdopen (int fd, const char *mode); /*
librock_z_gzdopen() associates a librock_z_gzFile with the file descriptor @fd. File descriptors are obtained from calls like @open, @dup, @creat, @pipe or @fileno (in the file has been previously opened with @fopen ). The @mode parameter is as in @librock_z_gzopen(). The next call of @librock_z_gzclose on the returned @librock_z_gzFile will also close the file descriptor @fd, just like @fclose(fdopen(fd, @mode)) closes the file descriptor @fd. If you want to keep @fd open, use @librock_z_gzdopen(dup(fd), @mode) . @librock_z_gzdopen returns NULL if there was insufficient memory to allocate the (de)compression state.
*/ int librock_z_gzsetparams (librock_z_gzFile file, int level, int strategy); /*
Dynamically update the compression level or strategy. See the description of @librock_z_deflateInit2 for the meaning of these parameters. @librock_z_gzsetparams returns @librock_Z_OK if success, or @librock_Z_STREAM_ERROR if the file was not opened for writing.
*/ int librock_z_gzread (librock_z_gzFile file, librock_z_voidp buf, unsigned len); /*
Reads the given number of uncompressed bytes from the compressed file. If the input file was not in gzip format, @librock_z_gzread copies the given number of bytes into the buffer. @librock_z_gzread returns the number of uncompressed bytes actually read (0 for end of file, -1 for error).
*/ int librock_z_gzwrite (librock_z_gzFile file, const librock_z_voidp buf, unsigned len); /*
Writes the given number of uncompressed bytes into the compressed file. @librock_z_gzwrite returns the number of uncompressed bytes actually written (0 in case of error).
*/ int librock_z_gzprintf (librock_z_gzFile file, const char *format, ...); /*
Converts, formats, and writes the args to the compressed file under control of the @format string, as in @fprintf. @librock_z_gzprintf returns the number of uncompressed bytes actually written (0 in case of error). The default compile-time macro @librock_Z_PRINTF_BUFSIZE is 4096, which is the largest string which can be written without truncation. NOTE: A #define in librock/zconf.h librock forces zlib to compile with a call to @vsnprintf() (instead of @vsprintf(), or other overrun unsafe calls.)
*/ int librock_z_gzputs (librock_z_gzFile file, const char *s); /*
Writes the given NUL-terminated string to the compressed file, excluding the terminating NUL character. @librock_z_gzputs returns the number of characters written, or -1 in case of error.
*/ char * librock_z_gzgets (librock_z_gzFile file, char *buf, int len); /*
Reads bytes from the compressed file until @len-1 characters are read, or a newline character is read and transferred to buf, or an end-of-file condition is encountered. The string is then terminated with a NUL character. @librock_z_gzgets returns @buf, or @librock_Z_NULL in case of error.
*/ int librock_z_gzputc (librock_z_gzFile file, int c); /*
Writes @c, converted to an unsigned char, into the compressed file. @librock_z_gzputc returns the value that was written, or -1 in case of error.
*/ int librock_z_gzgetc (librock_z_gzFile file); /*
Reads one byte from the compressed file. @librock_z_gzgetc returns this byte or -1 in case of end of file or error.
*/ int librock_z_gzflush (librock_z_gzFile file, int flush); /*
Flushes all pending output into the compressed file. The parameter @flush is as in the @librock_z_deflate() function. The return value is the @librock_zlib error number (see function @librock_z_gzerror below). @librock_z_gzflush returns @librock_Z_OK if the @flush parameter is @librock_Z_FINISH and all output could be flushed. @librock_z_gzflush() should be called only when strictly necessary because it can degrade compression.
*/ librock_z_off_t librock_z_gzseek (librock_z_gzFile file, librock_z_off_t offset, int whence); /*
Sets the starting position for the next @librock_z_gzread or @librock_z_gzwrite on the given compressed file. The @offset represents a number of bytes in the uncompressed data stream. The @whence parameter is defined as in @lseek(2) ; the value @SEEK_END is not supported. If the file is opened for reading, this function is emulated but can be extremely slow. If the file is opened for writing, only forward seeks are supported; @librock_z_gzseek then compresses a sequence of zeroes up to the new starting position. @librock_z_gzseek returns the resulting offset location as measured in bytes from the beginning of the uncompressed stream, or -1 in case of error, in particular if the file is opened for writing and the new starting position would be before the current position.
*/ int librock_z_gzrewind (librock_z_gzFile file); /*
Rewinds the given file. This function is supported only for reading. @librock_z_gzrewind(file) is equivalent to @(int)librock_z_gzseek(file, @0L, @SEEK_SET)
*/ librock_z_off_t librock_z_gztell (librock_z_gzFile file); /*
Returns the starting position for the next @librock_z_gzread or @librock_z_gzwrite on the given compressed file. This position represents a number of bytes in the uncompressed data stream. @librock_z_gztell(file) is equivalent to @librock_z_gzseek(file, @0L, @SEEK_CUR)
*/ int librock_z_gzeof (librock_z_gzFile file); /*
Returns 1 when @EOF has previously been detected reading the given input stream, otherwise zero.
*/ int librock_z_gzclose (librock_z_gzFile file); /*
Flushes all pending output if necessary, closes the compressed file and deallocates all the (de)compression state. The return value is the librock_zlib error number (see function @librock_z_gzerror() below).
*/ const char * librock_z_gzerror (librock_z_gzFile file, int *errnum); /*
Returns the error message for the last error which occurred on the given compressed file. @errnum is set to librock_zlib error number. If an error occurred in the file system and not in the compression library, errnum is set to @librock_Z_ERRNO and the application may consult @errno to get the exact error code.
*/ /*
Typical use is */ void test_gzio(out, in, uncompr, uncomprLen) const char *out; /* compressed output file */ const char *in; /* compressed input file */ librock_z_Byte *uncompr; int uncomprLen; { int err; int len = strlen(hello)+1; librock_z_gzFile file; librock_z_off_t pos; file = librock_z_gzopen(out, "wb"); if (file == NULL) { fprintf(stderr, "gzopen error\n"); exit(1); } librock_z_gzputc(file, 'h'); if (librock_z_gzputs(file, "ello") != 4) { fprintf(stderr, "gzputs err: %s\n", librock_z_gzerror(file, &err)); exit(1); } if (librock_z_gzprintf(file, ", %s!", "hello") != 8) { fprintf(stderr, "gzprintf err: %s\n", librock_z_gzerror(file, &err)); exit(1); } librock_z_gzseek(file, 1L, SEEK_CUR); /* add one zero librock_z_Byte */ librock_z_gzclose(file); file = librock_z_gzopen(in, "rb"); if (file == NULL) { fprintf(stderr, "gzopen error\n"); } uncomprLen = librock_z_gzread(file, uncompr, (unsigned)uncomprLen); if (uncomprLen != len) { fprintf(stderr, "gzread err: %s\n", librock_z_gzerror(file, &err)); exit(1); } /* Work with uncompr here */ printf("gzread(): %s\n", (char *)uncompr); pos = librock_z_gzseek(file, -8L, SEEK_CUR); if (pos != 6 || librock_z_gztell(file) != pos) { fprintf(stderr, "gzseek error, pos=%ld, librock_z_gztell=%ld\n", (long)pos, (long)librock_z_gztell(file)); exit(1); } if (librock_z_gzgetc(file) != ' ') { fprintf(stderr, "gzgetc error\n"); exit(1); } librock_z_gzgets(file, (char*)uncompr, uncomprLen); uncomprLen = strlen((char*)uncompr); printf("gzgets() after gzseek: %s\n", (char *)uncompr); librock_z_gzclose(file); } /* librock_z_crc32 librock_z_deflate librock_z_deflateEnd librock_z_deflateInit2_ librock_z_deflateParams librock_z_errmsg librock_z_inflate librock_z_inflateEnd librock_z_inflateInit2_ librock_z_inflateReset fdopen errno fclose fflush fopen fprintf fputc fread free fseek ftell fwrite malloc memcpy memset rewind sprintf // During gz_fdopen for debugging. buffer-overrun safe if sizeof(int) <= 4 strcat strcpy strlen vsnprintf // called by librock_z_gzprintf only librock_CHISEL _bodysrc ./acquired/zlib/adler32.c librock_CHISEL _bodysrc ./acquired/zlib/zcrc32.c librock_CHISEL _bodysrc ./acquired/zlib/compress.c librock_CHISEL _bodysrc ./acquired/zlib/deflate.c librock_CHISEL _bodysrc ./acquired/zlib/deflate.h librock_CHISEL _bodysrc ./acquired/zlib/gzio.c librock_CHISEL _bodysrc ./acquired/zlib/infblock.c librock_CHISEL _bodysrc ./acquired/zlib/infblock.h librock_CHISEL _bodysrc ./acquired/zlib/infcodes.c librock_CHISEL _bodysrc ./acquired/zlib/infcodes.h librock_CHISEL _bodysrc ./acquired/zlib/inffast.c librock_CHISEL _bodysrc ./acquired/zlib/inffast.h librock_CHISEL _bodysrc ./acquired/zlib/inffixed.h librock_CHISEL _bodysrc ./acquired/zlib/inflate.c librock_CHISEL _bodysrc ./acquired/zlib/inftrees.c librock_CHISEL _bodysrc ./acquired/zlib/inftrees.h librock_CHISEL _bodysrc ./acquired/zlib/infutil.c librock_CHISEL _bodysrc ./acquired/zlib/infutil.h librock_CHISEL _bodysrc ./acquired/zlib/trees.h librock_CHISEL _bodysrc ./acquired/zlib/uncompr.c librock_CHISEL _bodysrc ./acquired/zlib/zconf.h librock_CHISEL _bodysrc ./acquired/zlib/zlib.h librock_CHISEL _bodysrc ./acquired/zlib/ztrees.c librock_CHISEL _bodysrc ./acquired/zlib/zutil.c librock_CHISEL _bodysrc ./acquired/zlib/zutil.h librock_CHISEL _bodysrc ./librock/zlibh.h */ /* These functions are well-behaved in multi-threaded environments. The zlib functions do not install any signal handler, and return error codes instead of exiting or throwing exceptions. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. */ /* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ /**************************************************************/ #endif /* MANUAL */ typedef librock_z_voidp librock_z_gzFile; librock_ZEXTERN librock_z_gzFile librock_ZEXPORT librock_z_gzopen librock_z_OF((const char *path, const char *mode)); librock_ZEXTERN librock_z_gzFile librock_ZEXPORT librock_z_gzdopen librock_z_OF((int fd, const char *mode)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzsetparams librock_z_OF((librock_z_gzFile file, int level, int strategy)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzread librock_z_OF((librock_z_gzFile file, librock_z_voidp buf, unsigned len)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzwrite librock_z_OF((librock_z_gzFile file, const librock_z_voidp buf, unsigned len)); librock_ZEXTERN int librock_ZEXPORTVA librock_z_gzprintf librock_z_OF((librock_z_gzFile file, const char *format, ...)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzputs librock_z_OF((librock_z_gzFile file, const char *s)); librock_ZEXTERN char * librock_ZEXPORT librock_z_gzgets librock_z_OF((librock_z_gzFile file, char *buf, int len)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzputc librock_z_OF((librock_z_gzFile file, int c)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzgetc librock_z_OF((librock_z_gzFile file)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzflush librock_z_OF((librock_z_gzFile file, int flush)); librock_ZEXTERN librock_z_off_t librock_ZEXPORT librock_z_gzseek librock_z_OF((librock_z_gzFile file, librock_z_off_t offset, int whence)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzrewind librock_z_OF((librock_z_gzFile file)); librock_ZEXTERN librock_z_off_t librock_ZEXPORT librock_z_gztell librock_z_OF((librock_z_gzFile file)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzeof librock_z_OF((librock_z_gzFile file)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzclose librock_z_OF((librock_z_gzFile file)); librock_ZEXTERN const char * librock_ZEXPORT librock_z_gzerror librock_z_OF((librock_z_gzFile file, int *errnum)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateInit_ librock_z_OF((librock_z_streamp strm, int level, const char *version, int stream_size)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateInit_ librock_z_OF((librock_z_streamp strm, const char *version, int stream_size)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateInit2_ librock_z_OF((librock_z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateInit2_ librock_z_OF((librock_z_streamp strm, int windowBits, const char *version, int stream_size)); librock_ZEXTERN const char * librock_ZEXPORT librock_z_zlibVersion librock_z_OF((void)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateInit librock_z_OF((librock_z_streamp strm, int level)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflate librock_z_OF((librock_z_streamp strm, int flush)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateEnd librock_z_OF((librock_z_streamp strm)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateInit librock_z_OF((librock_z_streamp strm)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflate librock_z_OF((librock_z_streamp strm, int flush)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateEnd librock_z_OF((librock_z_streamp strm)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateInit2 librock_z_OF((librock_z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateSetDictionary librock_z_OF((librock_z_streamp strm, const librock_z_Bytef *dictionary, librock_z_uInt dictLength)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateCopy librock_z_OF((librock_z_streamp dest, librock_z_streamp source)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateReset librock_z_OF((librock_z_streamp strm)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateParams librock_z_OF((librock_z_streamp strm, int level, int strategy)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateInit2 librock_z_OF((librock_z_streamp strm, int windowBits)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateSetDictionary librock_z_OF((librock_z_streamp strm, const librock_z_Bytef *dictionary, librock_z_uInt dictLength)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateSync librock_z_OF((librock_z_streamp strm)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateReset librock_z_OF((librock_z_streamp strm)); librock_ZEXTERN int librock_ZEXPORT librock_z_compress librock_z_OF((librock_z_Bytef *dest, librock_z_uLongf *destLen, const librock_z_Bytef *source, librock_z_uLong sourceLen)); librock_ZEXTERN int librock_ZEXPORT librock_z_compress2 librock_z_OF((librock_z_Bytef *dest, librock_z_uLongf *destLen, const librock_z_Bytef *source, librock_z_uLong sourceLen, int level)); librock_ZEXTERN int librock_ZEXPORT librock_z_uncompress librock_z_OF((librock_z_Bytef *dest, librock_z_uLongf *destLen, const librock_z_Bytef *source, librock_z_uLong sourceLen)); librock_ZEXTERN librock_z_gzFile librock_ZEXPORT librock_z_gzopen librock_z_OF((const char *path, const char *mode)); librock_ZEXTERN librock_z_gzFile librock_ZEXPORT librock_z_gzdopen librock_z_OF((int fd, const char *mode)); librock_ZEXTERN int librock_ZEXPORT librock_z_gzsetparams librock_z_OF((librock_z_gzFile file, int level, int strategy)); librock_ZEXTERN librock_z_uLong librock_ZEXPORT librock_z_adler32 librock_z_OF((librock_z_uLong adler, const librock_z_Bytef *buf, librock_z_uInt len)); librock_ZEXTERN librock_z_uLong librock_ZEXPORT librock_z_crc32 librock_z_OF((librock_z_uLong crc, const librock_z_Bytef *buf, librock_z_uInt len)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateInit_ librock_z_OF((librock_z_streamp strm, int level, const char *version, int stream_size)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateInit_ librock_z_OF((librock_z_streamp strm, const char *version, int stream_size)); librock_ZEXTERN int librock_ZEXPORT librock_z_deflateInit2_ librock_z_OF((librock_z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateInit2_ librock_z_OF((librock_z_streamp strm, int windowBits, const char *version, int stream_size)); librock_ZEXTERN const char * librock_ZEXPORT librock_z_zError librock_z_OF((int err)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateSyncPoint librock_z_OF((librock_z_streamp z)); librock_ZEXTERN const librock_z_uLongf * librock_ZEXPORT librock_z_get_crc_table librock_z_OF((void)); librock_ZEXTERN const char * librock_ZEXPORT librock_z_zError librock_z_OF((int err)); librock_ZEXTERN int librock_ZEXPORT librock_z_inflateSyncPoint librock_z_OF((librock_z_streamp z)); librock_ZEXTERN const librock_z_uLongf * librock_ZEXPORT librock_z_get_crc_table librock_z_OF((void)); /* various hacks, don't look :) */ /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of librock_z_stream: */ #define librock_z_deflateInit(strm, level) \ librock_z_deflateInit_((strm), (level), librock_ZLIB_VERSION, sizeof(librock_z_stream)) #define librock_z_inflateInit(strm) \ librock_z_inflateInit_((strm), librock_ZLIB_VERSION, sizeof(librock_z_stream)) #define librock_z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ librock_z_deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ (strategy), librock_ZLIB_VERSION, sizeof(librock_z_stream)) #define librock_z_inflateInit2(strm, windowBits) \ librock_z_inflateInit2_((strm), (windowBits), librock_ZLIB_VERSION, sizeof(librock_z_stream)) #ifdef __cplusplus } #endif #endif /* _ZLIB_H */