Skip to content
REFERENCE / ZLIB × LEAN

zlib API manual

Source snapshot · ea5942242974f0b2 · Source at the matching commit ↗

Documentation / API manual

Start here to find a zlib function, understand its caller obligations, or follow a stream's lifetime. Each entry gives the C signature, purpose, Pre (requirements), Post (result), Effects (permitted changes), and edge cases that affect use.

Choose a starting point

If you want to… Read
Understand the contract vocabulary and build scope How to read a contract
Manage buffers, ownership, resets and stream call order Shared stream rules
Compress incrementally through z_stream Stream compression
Decompress incrementally through z_stream Stream decompression
Supply decompression input and receive output through callbacks Callback decompression
Compress or decompress a whole buffer, or query the library Buffer utilities and library information
Compute or combine Adler-32 and CRC-32 checksums Checksums
Read, write, position or close a gzip file handle Gzip files

The manual follows the pinned source plus the listed patches, first for the default LP64 Linux static build and default allocator. Entries state their additional limits. The Windows gzopen_w entry is separate from that build. These are focused documentary contracts; some preconditions are narrower than the public header. Outside a stated Pre is outside that contract, not automatically undefined C. See scope deviations.

The behavior read from C is unfinished by implementation proof. This manual does not report completed verification or change the broader registered public goals. Progress is the single record of proof status and remaining work.

Find a function

The following index links all 96 entries, grouped by how they are used. The function pages retain C names, including trailing underscores supplied by initialization macros.

Stream compression

Function One line
deflateInit_ initialise with default window, memory level and strategy
deflateInit2_ initialise with all parameters
deflateSetDictionary preload a dictionary
deflateGetDictionary copy out the current dictionary window
deflateResetKeep restart a stream but keep the window and hash (undocumented)
deflateReset restart a stream
deflateSetHeader give the gzip header to write
deflatePending report pending output
deflateUsed report the bits used in the last byte of the last flush
deflatePrime insert bits into the output
deflateParams change level and strategy
deflateTune set the internal match-search tuning values
deflateBound_z upper bound on the compressed size (size type)
deflateBound upper bound on the compressed size (uLong)
deflate compress
deflateEnd free the stream
deflateCopy duplicate a stream

Stream decompression

Function One line
inflateResetKeep restart a stream and keep the window contents (undocumented)
inflateReset restart a stream, drop the window contents
inflateReset2 restart a stream with a new window size
inflateInit2_ initialise with a window size
inflateInit_ initialise with the default window size
inflatePrime insert bits into the input
inflate decompress
inflateEnd free the stream
inflateGetDictionary copy out the window
inflateSetDictionary give the dictionary
inflateGetHeader ask for the gzip header
inflateSync search for a full flush point
inflateSyncPoint test whether stopped at a sync flush point
inflateCopy duplicate a stream
inflateUndermine request distance-checking option; default build returns Z_DATA_ERROR
inflateValidate control wrapper integrity checks
inflateMark report where inflate is inside a block or code
inflateCodesUsed report the code table entries used by the current block (undocumented)

Callback decompression

Function One line
inflateBackInit_ initialise for callback decompression
inflateBack decompress with input and output callbacks
inflateBackEnd free the stream

Whole-buffer operations and library information

Function One line
compress2_z compress a buffer at a level (size type)
compress2 compress a buffer at a level
compress_z compress a buffer at the default level (size type)
compress compress a buffer at the default level
compressBound_z bound on the compressed size (size type)
compressBound bound on the compressed size
uncompress2_z decompress a buffer, report input used (size type)
uncompress2 decompress a buffer, report input used
uncompress_z decompress a buffer (size type)
uncompress decompress a buffer
zlibVersion the release string of the library
zlibCompileFlags the type sizes and options the library was built with
zError text for a return code

Checksums

Function One line
adler32_z Adler-32 of a buffer (size type)
adler32 Adler-32 of a buffer
adler32_combine combine two Adler-32 values
adler32_combine64 combine two Adler-32 values (64-bit length)
get_crc_table the CRC-32 table
crc32_z CRC-32 of a buffer (size type)
crc32 CRC-32 of a buffer
crc32_combine_gen64 operator for combining (64-bit length)
crc32_combine_gen operator for combining
crc32_combine_op combine with an operator
crc32_combine64 combine two CRC-32 values (64-bit length)
crc32_combine combine two CRC-32 values

Gzip files

Function One line
gzopen, gzopen64, gzdopen, gzopen_w open a file
gzbuffer, gzsetparams buffer size, compression parameters
gzread, gzfread, gzgetc, gzgetc_, gzungetc, gzgets read
gzwrite, gzfwrite, gzputc, gzputs, gzprintf, gzvprintf, gzflush write
gzrewind, gzseek, gzseek64, gztell, gztell64, gzoffset, gzoffset64 position
gzeof, gzdirect, gzerror, gzclearerr state
gzclose, gzclose_r, gzclose_w close

Build variants and macros

Compared with the functions that zlib.h declares, these are not compiled into the default Linux library:

Name Why
gzopen_w declared only for Windows (_WIN32); the definition in gzlib.c is under the wide-character option
deflateInit, deflateInit2, inflateInit, inflateInit2, inflateBackInit these are macros in zlib.h; they call deflateInit_, deflateInit2_, inflateInit_, inflateInit2_, inflateBackInit_ with the header's own release string and sizeof(z_stream)
gzgetc as a macro zlib.h also defines gzgetc as a macro that reads the buffer directly and calls gzgetc_ when empty; the function gzgetc exists as well

The index contains all 95 default-build entries and the separate Windows entry gzopen_w. Internal helper contracts describe routines used inside the library.

ZLIB × LEAN

Global contents

READING NOWzlib API manual