📄 zlib.html
字号:
<html><head> <title> zlib general purpose compression library version 1.1.4 </title></head><body bgcolor="White" text="Black" vlink="Red" alink="Navy" link="Red"><!-- background="zlibbg.gif" --><h1> zlib 1.1.4 Manual </h1><hr><a name="Contents"><h2>Contents</h2><ol type="I"><li> <a href="#Prologue">Prologue</a><li> <a href="#Introduction">Introduction</a><li> <a href="#Utility functions">Utility functions</a><li> <a href="#Basic functions">Basic functions</a><li> <a href="#Advanced functions">Advanced functions</a><li> <a href="#Constants">Constants</a><li> <a href="#struct z_stream_s">struct z_stream_s</a><li> <a href="#Checksum functions">Checksum functions</a><li> <a href="#Misc">Misc</a></ol><hr><a name="Prologue"><h2> Prologue </h2> 'zlib' general purpose compression library version 1.1.4, March 11th, 2002 <p> Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler <p> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. <p> Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: <ol> <li> The origin of this software must not be misrepresented ; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. <li> Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. <li> This notice may not be removed or altered from any source distribution. </ol> <dl> <dt>Jean-loup Gailly <dd><a href="mailto:jloup@gzip.org">jloup@gzip.org</a> <dt>Mark Adler <dd><a href="mailto:madler@alumni.caltech.edu">madler@alumni.caltech.edu</a> </dl> The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files <a href="ftp://ds.internic.net/rfc/rfc1950.txt"> ftp://ds.internic.net/rfc/rfc1950.txt </a> (zlib format), <a href="ftp://ds.internic.net/rfc/rfc1951.txt"> rfc1951.txt </a> (<a href="#deflate">deflate</a> format) and <a href="ftp://ds.internic.net/rfc/rfc1952.txt"> rfc1952.txt </a> (gzip format). <p> This manual is converted from zlib.h by <a href="mailto:piaip@csie.ntu.edu.tw"> piaip </a> <p> Visit <a href="http://ftp.cdrom.com/pub/infozip/zlib/"> http://ftp.cdrom.com/pub/infozip/zlib/</a> for the official zlib web page. <p><hr><a name="Introduction"><h2> Introduction </h2> 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. <p> Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done 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. <p> The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio. <p> The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. <p><hr><a name="Utility functions"><h2> Utility functions </h2> The following utility functions are implemented on top of the <a href="#Basic functions">basic stream-oriented functions</a>. To simplify the interface, some default options are assumed (compression level and memory usage, standard memory allocation functions). The source code of these utility functions can easily be modified if you need special options.<h3> Function list </h3><ul><li> int <a href="#compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);<li> int <a href="#compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);<li> int <a href="#uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);<li> typedef voidp gzFile;<li> gzFile <a href="#gzopen">gzopen</a> (const char *path, const char *mode);<li> gzFile <a href="#gzdopen">gzdopen</a> (int fd, const char *mode);<li> int <a href="#gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);<li> int <a href="#gzread">gzread</a> (gzFile file, voidp buf, unsigned len);<li> int <a href="#gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);<li> int VA <a href="#gzprintf">gzprintf</a> (gzFile file, const char *format, ...);<li> int <a href="#gzputs">gzputs</a> (gzFile file, const char *s);<li> char * <a href="#gzgets">gzgets</a> (gzFile file, char *buf, int len);<li> int <a href="#gzputc">gzputc</a> (gzFile file, int c);<li> int <a href="#gzgetc">gzgetc</a> (gzFile file);<li> int <a href="#gzflush">gzflush</a> (gzFile file, int flush);<li> z_off_t <a href="#gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);<li> z_off_t <a href="#gztell">gztell</a> (gzFile file);<li> int <a href="#gzrewind">gzrewind</a> (gzFile file);<li> int <a href="#gzeof">gzeof</a> (gzFile file);<li> int <a href="#gzclose">gzclose</a> (gzFile file);<li> const char * <a href="#gzerror">gzerror</a> (gzFile file, int *errnum);</ul><h3> Function description </h3><dl><font color="Blue"><dt> int <a name="compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font><dd> Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.<p> This function can be used to <a href="#compress">compress</a> a whole file at once if the input file is mmap'ed.<p> <a href="#compress">compress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer.<p><font color="Blue"><dt> int <a name="compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);</font><dd> Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in <a href="#deflateInit">deflateInit</a>. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. <p> <a href="#compress2">compress2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the level parameter is invalid. <p><font color="Blue"><dt> int <a name="uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font><dd> Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (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, destLen is the actual size of the compressed buffer. <p> This function can be used to decompress a whole file at once if the input file is mmap'ed. <p> <a href="#uncompress">uncompress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer, or <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was corrupted. <p><dt> typedef voidp gzFile;<dd> <p><font color="Blue"><dt> gzFile <a name="gzopen">gzopen</a> (const char *path, const char *mode);</font><dd> Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen ("rb" or "wb") but can also include a compression level ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman only compression as in "wb1h". (See the description of <a href="#deflateInit2">deflateInit2</a> for more information about the strategy parameter.) <p> <a href="#gzopen">gzopen</a> can be used to read a file which is not in gzip format ; in this case <a href="#gzread">gzread</a> will directly read from the file without decompression. <p> <a href="#gzopen">gzopen</a> returns NULL if the file could not be opened or if there was insufficient memory to allocate the (de)compression <a href="#state">state</a> ; errno can be checked to distinguish the two cases (if errno is zero, the zlib error is <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a>). <p><font color="Blue"><dt> gzFile <a name="gzdopen">gzdopen</a> (int fd, const char *mode);</font><dd> <a href="#gzdopen">gzdopen</a>() associates a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (in the file has been previously opened with fopen). The mode parameter is as in <a href="#gzopen">gzopen</a>. <p> The next call of <a href="#gzclose">gzclose</a> on the returned gzFile will also close the file descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor fd. If you want to keep fd open, use <a href="#gzdopen">gzdopen</a>(dup(fd), mode). <p> <a href="#gzdopen">gzdopen</a> returns NULL if there was insufficient memory to allocate the (de)compression <a href="#state">state</a>. <p><font color="Blue"><dt> int <a name="gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);</font><dd> Dynamically update the compression level or strategy. See the description
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -