zlib Data Types

Syntax

#include <cafe.h>
        
#include <zlib.h>

#define ZLIB_VERSION "1.2.5"
#define ZLIB_VERNUM 0x1250

typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
 
struct internal_state;
 
typedef struct z_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 */
 
    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: binary or text */
    uLong   adler;      /* adler32 value of the uncompressed data */
    uLong   reserved;   /* reserved for future use */
} z_stream;
 
typedef z_stream FAR *z_streamp;
 
typedef struct gz_header_s {
    int     text;       /* true if compressed data believed to be text */
    uLong   time;       /* modification time */
    int     xflags;     /* extra flags (not used when writing a gzip file) */
    int     os;         /* operating system */
    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
    uInt    extra_max;  /* space at extra (only when reading header) */
    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
    uInt    name_max;   /* space at name (only when reading header) */
    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
    uInt    comm_max;   /* space at comment (only when reading header) */
    int     hcrc;       /* true if there was or will be a header crc */
    int     done;       /* true when done reading gzip header (not used
                           when writing a gzip file) */
} gz_header;
 
typedef gz_header FAR *gz_headerp;

#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO        (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR    (-4)
#define Z_BUF_ERROR    (-5)
#define Z_VERSION_ERROR (-6)

#define Z_NO_COMPRESSION         0
#define Z_BEST_SPEED             1
#define Z_BEST_COMPRESSION       9
#define Z_DEFAULT_COMPRESSION  (-1)

#define Z_FILTERED            1
#define Z_HUFFMAN_ONLY        2
#define Z_RLE                 3
#define Z_FIXED               4
#define Z_DEFAULT_STRATEGY    0

#define Z_BINARY   0
#define Z_TEXT     1
#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN  2

#define Z_DEFLATED   8

#define Z_NULL  0

#define zlib_version zlibVersion()

Elements

z_stream

next_in Pointer to next input byte.
avail_in Number of bytes available at next_in.
total_in Total number of input bytes read so far.
next_out Pointer to next output byte.
avail_out remaining free space at next_out.
total_out total number of bytes output so far.
msg Pointer to last error message, NULL if no error.
state Not visible by applications.
zalloc Used to allocate the internal state.
zfree Used to free the internal state.
opaque Private data object passed to zalloc and zfree.
data_type Best guess about the data type: binary or text.
adler adler32 value of the uncompressed data.
reserved Reserved for future use.

gz_header

textTRUE if compressed data believed to be text.
timeModification time.
xflagsExtra flags (not used when writing a gzip file).
osOperating system.
extraPointer to extra field or Z_NULL if none.
extra_lenExtra field length (valid if extra != Z_NULL).
extra_maxSpace at extra (only when reading header).
namePointer to zero-terminated file name or Z_NULL.
name_maxSpace at name (only when reading header).
commentPointer to zero-terminated comment or Z_NULL.
comm_maxSpace at comment (only when reading header).
hcrcTRUE if there was or will be a header crc.
doneTRUE when done reading gzip header (not used when writing a gzip file).

Description

z_stream

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 multithreaded 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 MS-DOS, 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).

gz_header

gzip header information passed to and from zlib routines. See RFC 1952 for more information about the meanings of these fields.

Constants

Allowed flush values. For more information, see deflate and inflate.

#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

Return codes for the compression/decompression functions. Negative values are errors, positive values are used for special but normal events.

#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO        (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR    (-4)
#define Z_BUF_ERROR    (-5)
#define Z_VERSION_ERROR (-6)

Compression levels.

#define Z_NO_COMPRESSION         0
#define Z_BEST_SPEED             1
#define Z_BEST_COMPRESSION       9
#define Z_DEFAULT_COMPRESSION  (-1)

Compression strategy. For more information, see deflateInit2.

#define Z_FILTERED            1
#define Z_HUFFMAN_ONLY        2
#define Z_RLE                 3
#define Z_FIXED               4
#define Z_DEFAULT_STRATEGY    0

Possible values of the data_type field (though see inflate).

#define Z_BINARY   0
#define Z_TEXT     1
#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN  2

The deflate compression method (the only one supported in this version).

#define Z_DEFLATED   8

For initializing zalloc, zfree, opaque.

#define Z_NULL  0

For compatibility with versions < 1.0.2.

#define zlib_version zlibVersion()

See Also

zlib Overview

Revision History

2014/12/05 Creation.


CONFIDENTIAL