This manual was created by modifying the zlib manual.
Visit http://cis.poly.edu/zdelta for the official zdelta web page.
This function can be used to zd_compress a whole file at once if the input file is mmap'ed.
zd_compress returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, ZD_BUF_ERROR if there was not enough room in the output buffer.
This function can be used to zd_compress1 a whole file at once if the input file is mmap'ed.
zd_compress1 returns Z_OK if success, Z_MEM_ERROR if there was not enough memory.
This function can be used to zd_compressN a whole file at once if the input file is mmap'ed.
zd_compress returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, ZD_BUF_ERROR if there was not enough room in the output buffer.
This function can be used to zd_compressN1 a whole file at once if the input file is mmap'ed.
zd_compress returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory.
This function can be used to zd_uncompress1 a whole file at once if the input file is mmap'ed.
zd_uncompress1 returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, or ZD_DATA_ERROR if the input data was corrupted.Upon entry, tsize is the total byte length of the target buffer (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, tsize is the byte length of the uncompressed data in the tar buffer.
This function can be used to zd_uncompressN a whole file at once if the input file is mmap'ed.zd_uncompressN returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, ZD_BUF_ERROR if there was not enough room in the output buffer, or ZD_DATA_ERROR if the input data was corrupted.
zd_uncompressN1 returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, or ZD_DATA_ERROR if the input data was corrupted.
The compression level must be ZD_DEFAULT_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).
ZD_DEFAULT_COMPRESSION requests a default compromise between speed and compression (currently equivalent to level 6).
zd_deflateInit returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, ZD_STREAM_ERROR if level is not a valid compression level, ZD_VERSION_ERROR if the zdlib library version (zdlib_version) is incompatible with the version assumed by the caller (ZDLIB_VERSION). msg is set to null if there is no error message. zd_deflateInit does not perform any compression: this will be done by zd_deflate().
The detailed semantics are as follows. zd_deflate performs one or both of the following actions:
Before the call of zd_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 avail_in or avail_out accordingly ; 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 (avail_out == 0), or after each call of zd_deflate(). If zd_deflate returns ZD_OK and with zero 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 ZD_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 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 ZD_FULL_FLUSH, all output is flushed as with 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 ZD_FULL_FLUSH too often can seriously degrade the compression.
If zd_deflate returns with avail_out == 0, this function must be called again with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out).
If the parameter flush is set to ZD_FINISH, pending input is processed, pending output is flushed and zd_deflate returns with ZD_STREAM_END if there was enough output space ; if zd_deflate returns with ZD_OK, this function must be called again with ZD_FINISH and more output space (updated avail_out) but no more input data, until it returns with ZD_STREAM_END or an error. After zd_deflate has returned ZD_STREAM_END, the only possible operations on the stream are zd_deflateReset or zd_deflateEnd.
ZD_FINISH can be used immediately after zd_deflateInit if all the compression is to be done in a single step. In this case, avail_out must be at least 0.1% larger than avail_in plus 12 bytes. If deflate does not return ZD_STREAM_END, then it must be called again as described above.
zd_deflate() sets strm-> zd_adler to the zs_adler32 checksum of all input read so far (that is, total_in bytes).
zd_deflate() returns ZD_OK if some progress has been made (more input processed or more output produced), ZD_STREAM_END if all input has been consumed and all output has been produced (only when flush is set to ZD_FINISH), ZD_STREAM_ERROR if the stream state was inconsistent (for example if next_in or next_out was NULL), ZD_BUF_ERROR if no progress is possible (for example avail_in or avail_out was zero).
zd_deflateEnd returns ZD_OK if success, ZD_STREAM_ERROR if the stream state was inconsistent, ZD_DATA_ERROR if the stream was freed prematurely (some input or output was discarded). In the error case, msg may be set but then points to a static string (which must not be deallocated).
zd_inflateInit returns ZD_OK if success, ZD_MEM_ERROR if there was not enough memory, ZD_VERSION_ERROR if the zdlib library version is incompatible with the version assumed by the caller. msg is set to null if there is no error message. zd_inflateInit does not perform any decompression apart from reading the zdlib header if present: this will be done by zd_inflate(). (So next_in and avail_in may be modified, but next_out and avail_out are unchanged.)
The detailed semantics are as follows. zd_inflate performs one or both of the following actions:
Before the call of zd_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 next_* and avail_* values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of zd_inflate(). If zd_inflate returns ZD_OK and with zero 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 ZD_SYNC_FLUSH, zd_inflate flushes as much output as possible to the output buffer. The flushing behavior of inflate is not specified for values of the flush parameter other than ZD_SYNC_FLUSH and ZD_FINISH, but the current implementation actually flushes as much output as possible anyway.
zd_inflate() should normally be called until it returns ZD_STREAM_END or an error. However if all decompression is to be performed in a single step (a single call of zd_inflate), the parameter flush should be set to ZD_FINISH. In this case all pending input is processed and all pending output is flushed ; 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 zd_inflateEnd to deallocate the decompression state. The use of ZD_FINISH is never required, but can be used to inform inflate that a faster routine may be used for the single zd_inflate() call.
zd_inflate() sets strm-> adler to the adler32 checksum of all output produced so far (that is, total_out bytes) and returns ZD_OK, ZD_STREAM_END or an error code as described below. At the end of the stream, zd_inflate() checks that its computed zd_adler32 checksum is equal to that saved by the compressor and returns ZD_STREAM_END only if the checksum is correct.
zd_inflate() returns ZD_OK if some progress has been made (more input processed or more output produced), ZD_STREAM_END if the end of the compressed data has been reached and all uncompressed output has been produced, ZD_DATA_ERROR if the input data was corrupted (input stream not conforming to the zdlib format or incorrect adler32 checksum), ZD_STREAM_ERROR if the stream structure was inconsistent (for example if next_in or next_out was NULL), ZD_MEM_ERROR if there was not enough memory, ZD_BUF_ERROR if no progress is possible or if there was not enough room in the output buffer when ZD_FINISH is used. In the ZD_DATA_ERROR case, the application may then call zd_inflateSync to look for a good compression block.
zd_inflateEnd returns ZD_OK if success, ZD_STREAM_ERROR if the stream state was inconsistent. In the error case, msg may be set but then points to a static string (which must not be deallocated).
zd_deflateReset returns ZD_OK if success, or ZD_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being NULL).
Before the call of zd_deflateParams, the stream state must be set as for a call of zd_deflate(), since the currently available input may have to be compressed and flushed. In particular, strm-> avail_out must be non-zero.
zd_deflateParams returns ZD_OK if success, ZD_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, ZD_BUF_ERROR if strm->avail_out was zero.
zd_inflateSync returns ZD_OK if a full flush point has been found, ZD_BUF_ERROR if no more input was provided, ZD_DATA_ERROR if no flush point has been found, or ZD_STREAM_ERROR if the stream structure was inconsistent. In the success case, the application may save the current current value of total_in which indicates where valid compressed data was found. In the error case, the application may repeatedly call zd_inflateSync, providing more input each time, until success or end of the input data.
zd_inflateReset returns ZD_OK if success, or ZD_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being NULL).
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much faster. Usage example:
uLong adler = zd_adler32(0L, ZD_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = zd_adler32(adler, buffer, length);
}
if (adler != original_adler) error();
typedef struct zd_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
Bytef *base[REFNUM]; /* pointers to the reference/base buffers */
uLong base_out[REFNUM]; /* bytes read from the corresponding reference buffer */
uLong base_avail[REFNUM]; /* available bytes in the correspoing reference buffer */
int refnum; /* number of reference buffers */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* zd_adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} zd_stream ;
typedef zd_stream FAR * zd_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 ZD_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 this library 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).
#define ZD_NO_FLUSH 0 #define ZD_SYNC_FLUSH 2 #define ZD_FULL_FLUSH 3 #define ZD_FINISH 4 /* Allowed flush values ; see zd_deflate() below for details */ #define ZD_OK 0 #define ZD_STREAM_END 1 #define ZD_ERRNO (-1) #define ZD_STREAM_ERROR (-2) #define ZD_DATA_ERROR (-3) #define ZD_MEM_ERROR (-4) #define ZD_BUF_ERROR (-5) #define ZD_VERSION_ERROR (-6) /* Return codes for the compression/decompression functions. Negative * values are errors, positive values are used for special but normal events. */ #define ZD_NO_COMPRESSION 0 #define ZD_BEST_SPEED 1 #define ZD_BEST_COMPRESSION 9 #define ZD_DEFAULT_COMPRESSION (-1) /* compression levels */ #define ZD_FILTERED 5 #define ZD_HUFFMAN_ONLY 0 #define ZD_DEFAULT_STRATEGY 7 /* compression strategy ; see deflateInit2() below for details */ #define ZD_DEFLATED 8 /* The zd_deflate compression method (the only one supported in this version) */ #define ZD_NULL 0 /* for initializing zalloc, zfree, opaque */ #ifndef REFNUM #define REFNUM 1 /* reference window number; defaluts to 1; must be between 1 and 4 */ #endif
Other functions: