zlib Overview

Introduction

The zlib library is a publicly available, royalty and license free compression library.

There are no modifications to the publicly available compression library on the zlib website (http://www.zlib.net).

For information about the zlib license agreement, see zlib general purpose compression library.

Description

The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) but other algorithms will be added later and will have the same stream interface.

Compression can be performed in a single step if the buffers are large enough (for example if an input file is loaded in its entirety), or can be performed 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.

The compressed data format used by default by the in-memory functions is the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around a deflate stream, which is itself documented in RFC 1951.

The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even for corrupted input.

Supported API

Basic

zlibVersion Compare zlibVersion and ZLIB_VERSION for consistency.
deflateInit Initialize the internal stream state for compression.
deflate Compress as much data as possible, and stop when the input buffer becomes empty or the output buffer becomes full.
deflateEnd Discard any unprocessed input and do not flush any pending output.
inflateInit Initialize the internal stream state for decompression.
inflate Decompress as much data as possible, and stop when the input buffer becomes empty or the output buffer becomes full.
inflateEnd Free dynamically allocated data structures for this stream. Discard any unprocessed input and do not flush any pending output.

Advanced

deflateInit2 A version of deflateInit with more compression options.
deflateSetDictionary Initialize the compression dictionary from the given byte sequence without producing any compressed output.
deflateCopy Set the destination stream as a complete copy of the source stream.
deflateReset Equivalent to deflateEnd followed by deflateInit, but does not free and reallocate all the internal compression state.
deflateParams Dynamically update the compression level and compression strategy.
deflateTune Fine tune deflate's internal compression parameters.
deflateBound Return an upper bound on the compressed size after deflation of sourceLen bytes.
deflatePrime Insert bits in the deflate output stream.
deflateSetHeader Provides gzip header information for when a gzip stream is requested by deflateInit2.
inflateInit2 Version of inflateInit with an extra parameter.
inflateSetDictionary Initialize the decompression dictionary from the given uncompressed byte sequence.
inflateSync Skip invalid compressed data until a full flush point can be found, or until all available input is skipped. No output is provided.
inflateCopy Set the destination stream as a complete copy of the source stream.
inflateReset Equivalent to inflateEnd followed by inflateInit, but does not free and reallocate all the internal decompression state.
inflateReset2 Same as inflateReset, but it also permits changing the wrap and window size requests.
inflatePrime Insert bits in the inflate input stream.
inflateMark Return a stream position indicator (mark) or an indication that the source stream state is inconsistent.
inflateGetHeader Request that gzip header information be stored in the provided gz_header structure.
inflateBackInit Initialize the internal stream state for decompression using inflateBack calls.
inflateBack Perform a raw inflate with a single call using a callback interface for input and output.
inflateBackEnd Free all memory allocated by inflateBackInit.
zlibCompileFlags Return flags indicating compile-time options.

Utility

compress Compress the source buffer into the destination buffer.
compress2 Compress the source buffer into the destination buffer.
compressBound Return an upper bound on the compressed size after compress or compress2 on sourceLen bytes.
uncompress Decompress the source buffer into the destination buffer.

Checksum

adler32 Return a running Adler-32 style checksum.
crc32 Return a running CRC-32 style checksum.

Demos

There is a demonstration of usage of compression and decompression in the demo folder:

$CAFE_ROOT/system/src/demo/usezlib

A demonstration involving the parsing and extraction from a ZIP file created in Windows is in the demo folder:

$CAFE_ROOT/system/src/demo/zipfile

A demonstration in using the gzip command to compress and uncompress a file exists in the demo folder:

$CAFE_ROOT/system/src/demo/usegzip

Revision History

2014/12/05 Reorganize in standard style.
2014/03/04 Removed Undocumented Functions section.
2014/03/03 Removed 'gzip File Access Functions' and Prologue.
2013/06/25 Include the zlib manual.


CONFIDENTIAL