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;
当avail_in降到0时, 应用程序必须更新next_int和avail_in。当avail_out下降到0时,必须更新 next_out。
在调用初始化函数之前,应用程序必须初始化zalloc,zfree和opaque。其他所有字段都会被压缩库所赋值,而且
不会被应用程序更新。
应用程序提供的opaque的值将被作为调用zalloc和zfree的第一个参数传输出去,这样对配置内存管理器是
有好处的。
如果没有足够的内存空间分配给对象,zalloc必须返回Z_NULL,如果zlib被用作一个多线程应用,zalloc
和zfree必然是安全的。
在16位系统里,zalloc和zfree函数肯定可以分配65536字节的空间,但是如果MAXSEG_64K这个符号被
定义(参照zconf.h),将不会被要求分配更多的空间。警告:在MSDOS上,被zalloc返回的指针,它指向65536
个字节,必须将他们的偏移量规格化为0。被这个库提供的默认的分配函数确保了这些(参照zutil.c)。为了减少内
存需求和避免任何64K对象的分配,在消耗压缩比的情况下,用-DMAX_WBITS=14编译该库(参照zconf.h)。
total_in字段和total_out字段可以被用作统计或者进度报告。压缩完之后,total_in持有为压缩时的数据的
总大小,有可能会被保留用作解压装置。