📄 zlib.html
字号:
memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as an invalid method). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit2">deflateInit2</a> does not perform any compression: this will be done by <a href="#deflate">deflate</a>().<p> <font color="Blue"><dt> int <a name="deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font><dd> Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called immediately after <a href="#deflateInit">deflateInit</a>, <a href="#deflateInit2">deflateInit2</a> or <a href="#deflateReset">deflateReset</a>, before any call of <a href="#deflate">deflate</a>. The compressor and decompressor must use exactly the same dictionary (see <a href="#inflateSetDictionary">inflateSetDictionary</a>).<p> The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy ; the data can then be compressed better than with the default empty dictionary.<p> Depending on the size of the compression data structures selected by <a href="#deflateInit">deflateInit</a> or <a href="#deflateInit2">deflateInit2</a>, a part of the dictionary may in effect be discarded, for example if the dictionary is larger than the window size in <a href="#deflate">deflate</a> or deflate2. Thus the strings most likely to be useful should be put at the end of the dictionary, not at the front.<p> Upon return of this function, strm-> <a href="#adler">adler</a> is set to the Adler32 value of the dictionary ; the decompressor may later use this value to determine which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.)<p> <a href="#deflateSetDictionary">deflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is inconsistent (for example if <a href="#deflate">deflate</a> has already been called for this stream or if the compression method is bsort). <a href="#deflateSetDictionary">deflateSetDictionary</a> does not perform any compression: this will be done by <a href="#deflate">deflate</a>().<p><font color="Blue"><dt> int <a name="deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);</font><dd> Sets the destination stream as a complete copy of the source stream.<p> This function can be useful when several compression strategies will be tried, for example when there are several ways of pre-processing the input data with a filter. The streams that will be discarded should then be freed by calling <a href="#deflateEnd">deflateEnd</a>. Note that <a href="#deflateCopy">deflateCopy</a> duplicates the internal compression <a href="#state">state</a> which can be quite large, so this strategy is slow and can consume lots of memory.<p> <a href="#deflateCopy">deflateCopy</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_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> being NULL). <a href="#msg">msg</a> is left unchanged in both source and destination.<p><font color="Blue"><dt> int <a name="deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font><dd> This function is equivalent to <a href="#deflateEnd">deflateEnd</a> followed by <a href="#deflateInit">deflateInit</a>, but does not free and reallocate all the internal compression <a href="#state">state</a>. The stream will keep the same compression level and any other attributes that may have been set by <a href="#deflateInit2">deflateInit2</a>.<p> <a href="#deflateReset">deflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).<p><font color="Blue"><dt> int <a name="deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);</font><dd> Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in <a href="#deflateInit2">deflateInit2</a>. This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level (and may be flushed); the new level will take effect only at the next call of <a href="#deflate">deflate</a>().<p> Before the call of <a href="#deflateParams">deflateParams</a>, the stream <a href="#state">state</a> must be set as for a call of <a href="#deflate">deflate</a>(), since the currently available input may have to be compressed and flushed. In particular, strm-> <a href="#avail_out">avail_out</a> must be non-zero.<p> <a href="#deflateParams">deflateParams</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent or if a parameter was invalid, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if strm->avail_out was zero.<p><font color="Blue"><dt> int <a name="inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);</font><dd> This is another version of <a href="#inflateInit">inflateInit</a> with an extra parameter. The fields <a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by the caller.<p> The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. The default value is 15 if <a href="#inflateInit">inflateInit</a> is used instead. If a compressed stream with a larger window size is given as input, <a href="#inflate">inflate</a>() will return with the error code <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> instead of trying to allocate a larger window.<p> <a href="#inflateInit2">inflateInit2</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_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as a negative memLevel). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#inflateInit2">inflateInit2</a> does not perform any decompression apart from reading the zlib header if present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> may be modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)<p><font color="Blue"><dt> int <a name="inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font><dd> Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of <a href="#inflate">inflate</a> if this call returned <a href="#Z_NEED_DICT">Z_NEED_DICT</a>. The dictionary chosen by the compressor can be determined from the Adler32 value returned by this call of <a href="#inflate">inflate</a>. The compressor and decompressor must use exactly the same dictionary (see <a href="#deflateSetDictionary">deflateSetDictionary</a>).<p> <a href="#inflateSetDictionary">inflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the given dictionary doesn't match the expected one (incorrect Adler32 value). <a href="#inflateSetDictionary">inflateSetDictionary</a> does not perform any decompression: this will be done by subsequent calls of <a href="#inflate">inflate</a>().<p><font color="Blue"><dt> int <a name="inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);</font><dd> Skips invalid compressed data until a full flush point (see above the description of <a href="#deflate">deflate</a> with <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>) can be found, or until all available input is skipped. No output is provided.<p> <a href="#inflateSync">inflateSync</a> returns <a href="#Z_OK">Z_OK</a> if a full flush point has been found, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no more input was provided, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if no flush point has been found, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent. In the success case, the application may save the current current value of <a href="#total_in">total_in</a> which indicates where valid compressed data was found. In the error case, the application may repeatedly call <a href="#inflateSync">inflateSync</a>, providing more input each time, until success or end of the input data.<p><font color="Blue"><dt> int <a name="inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font><dd> This function is equivalent to <a href="#inflateEnd">inflateEnd</a> followed by <a href="#inflateInit">inflateInit</a>, but does not free and reallocate all the internal decompression <a href="#state">state</a>. The stream will keep attributes that may have been set by <a href="#inflateInit2">inflateInit2</a>. <p> <a href="#inflateReset">inflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL). <p></dl><hr><a name="Checksum functions"><h2> Checksum functions </h2> These functions are not related to compression but are exported anyway because they might be useful in applications using the compression library.<h3> Function list </h3><ul><li> uLong <a href="#adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);<li> uLong <a href="#crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);</ul><h3> Function description </h3><dl><font color="Blue"><dt> uLong <a name="adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);</font><dd> Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. If buf is NULL, this function returns the required initial value for the checksum. <p> An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much faster. Usage example: <pre> uLong <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0); while (read_buffer(buffer, length) != EOF) { <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(<a href="#adler">adler</a>, buffer, length); } if (<a href="#adler">adler</a> != original_adler) error(); </pre><font color="Blue"><dt> uLong <a name="crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);</font><dd> Update a running crc with the bytes buf[0..len-1] and return the updated crc. If buf is NULL, this function returns the required initial value for the crc. Pre- and post-conditioning (one's complement) is performed within this function so it shouldn't be done by the application. Usage example: <pre> uLong crc = <a href="#crc32">crc32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0); while (read_buffer(buffer, length) != EOF) { crc = <a href="#crc32">crc32</a>(crc, buffer, length); } if (crc != original_crc) error(); </pre></dl><hr><a name="struct z_stream_s"><h2> struct z_stream_s </h2><font color="Blue"><a name="z_stream_s"><pre>typedef struct z_stream_s { Bytef *<a name="next_in">next_in</a>; /* next input byte */ uInt <a name="avail_in">avail_in</a>; /* number of bytes available at <a href="#next_in">next_in</a> */ uLong <a name="total_in">total_in</a>; /* total nb of input bytes read so far */ Bytef *<a name="next_out">next_out</a>; /* next output byte should be put there */ uInt <a name="avail_out">avail_out</a>; /* remaining free space at <a href="#next_out">next_out</a> */ uLong <a name="total_out">total_out</a>; /* total nb of bytes output so far */ char *<a name="msg">msg</a>; /* last error message, NULL if no error */ struct internal_state FAR *<a name="state">state</a>; /* not visible by applications */ alloc_func <a name="zalloc">zalloc</a>; /* used to allocate the internal <a href="#state">state</a> */ free_func <a name="zfree">zfree</a>; /* used to free the internal <a href="#state">state</a> */ voidpf <a name="opaque">opaque</a>; /* private data object passed to <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> */ int <a name="data_type">data_type</a>; /* best guess about the data type: ascii or binary */ uLong <a name="adler">adler</a>; /* <a href="#adler32">adler32</a> value of the uncompressed data */ uLong <a name="reserved">reserved</a>; /* <a href="#reserved">reserved</a> for future use */} <a href="#z_stream_s">z_stream</a> ;typedef <a href="#z_stream_s">z_stream</a> FAR * <a name="z_streamp">z_streamp</a>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -