📄 zlib.html
字号:
If flush is set to <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>, all output is flushed as with <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, and the compression <a href="#state">state</a> is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a> too often can seriously degrade the compression. <p> If <a href="#deflate">deflate</a> returns with <a href="#avail_out">avail_out</a> == 0, this function must be called again with the same value of the flush parameter and more output space (updated <a href="#avail_out">avail_out</a>), until the flush is complete (<a href="#deflate">deflate</a> returns with non-zero <a href="#avail_out">avail_out</a>). <p> If the parameter flush is set to <a href="#Z_FINISH">Z_FINISH</a>, pending input is processed, pending output is flushed and <a href="#deflate">deflate</a> returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> if there was enough output space ; if <a href="#deflate">deflate</a> returns with <a href="#Z_OK">Z_OK</a>, this function must be called again with <a href="#Z_FINISH">Z_FINISH</a> and more output space (updated <a href="#avail_out">avail_out</a>) but no more input data, until it returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error. After <a href="#deflate">deflate</a> has returned <a href="#Z_STREAM_END">Z_STREAM_END</a>, the only possible operations on the stream are <a href="#deflateReset">deflateReset</a> or <a href="#deflateEnd">deflateEnd</a>. <p> <a href="#Z_FINISH">Z_FINISH</a> can be used immediately after <a href="#deflateInit">deflateInit</a> if all the compression is to be done in a single step. In this case, <a href="#avail_out">avail_out</a> must be at least 0.1% larger than <a href="#avail_in">avail_in</a> plus 12 bytes. If <a href="#deflate">deflate</a> does not return <a href="#Z_STREAM_END">Z_STREAM_END</a>, then it must be called again as described above. <p> <a href="#deflate">deflate</a>() sets strm-> <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all input read so far (that is, <a href="#total_in">total_in</a> bytes). <p> <a href="#deflate">deflate</a>() may update <a href="#data_type">data_type</a> if it can make a good guess about the input data type (<a href="#Z_ASCII">Z_ASCII</a> or <a href="#Z_BINARY">Z_BINARY</a>). In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner. <p> <a href="#deflate">deflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input processed or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if all input has been consumed and all output has been produced (only when flush is set to <a href="#Z_FINISH">Z_FINISH</a>), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a> was inconsistent (for example if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible (for example <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> was zero). <p><font color="Blue"><dt> int <a name="deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font><dd> All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output. <p> <a href="#deflateEnd">deflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a> was inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the stream was freed prematurely (some input or output was discarded). In the error case, <a href="#msg">msg</a> may be set but then points to a static string (which must not be deallocated). <p><font color="Blue"><dt> int <a name="inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);</font><dd> Initializes the internal stream <a href="#state">state</a> for decompression. 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. If <a href="#next_in">next_in</a> is not <a href="#Z_NULL">Z_NULL</a> and <a href="#avail_in">avail_in</a> is large enough (the exact value depends on the compression method), <a href="#inflateInit">inflateInit</a> determines the compression method from the zlib header and allocates all data structures accordingly ; otherwise the allocation will be deferred to the first call of <a href="#inflate">inflate</a>. If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#inflateInit">inflateInit</a> updates them to use default allocation functions. <p> <a href="#inflateInit">inflateInit</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_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version is incompatible with the version assumed by the caller. <a href="#msg">msg</a> is set to null if there is no error message. <a href="#inflateInit">inflateInit</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="inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font><dd> <a href="#inflate">inflate</a> decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may some introduce some output latency (reading input without producing any output) except when forced to flush. <p> The detailed semantics are as follows. <a href="#inflate">inflate</a> performs one or both of the following actions: <ul> <li> Decompress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> accordingly. If not all input can be processed (because there is not enough room in the output buffer), <a href="#next_in">next_in</a> is updated and processing will resume at this point for the next call of <a href="#inflate">inflate</a>(). <li> Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> accordingly. <a href="#inflate">inflate</a>() provides as much output as possible, until there is no more input data or no more space in the output buffer (see below about the flush parameter). </ul> <p> Before the call of <a href="#inflate">inflate</a>(), the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the next_* and avail_* values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (<a href="#avail_out">avail_out</a> == 0), or after each call of <a href="#inflate">inflate</a>(). If <a href="#inflate">inflate</a> returns <a href="#Z_OK">Z_OK</a> and with zero <a href="#avail_out">avail_out</a>, it must be called again after making room in the output buffer because there might be more output pending. <p> If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, <a href="#inflate">inflate</a> flushes as much output as possible to the output buffer. The flushing behavior of <a href="#inflate">inflate</a> is not specified for values of the flush parameter other than <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> and <a href="#Z_FINISH">Z_FINISH</a>, but the current implementation actually flushes as much output as possible anyway. <p> <a href="#inflate">inflate</a>() should normally be called until it returns <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error. However if all decompression is to be performed in a single step (a single call of <a href="#inflate">inflate</a>), the parameter flush should be set to <a href="#Z_FINISH">Z_FINISH</a>. In this case all pending input is processed and all pending output is flushed ; <a href="#avail_out">avail_out</a> must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been saved by the compressor for this purpose.) The next operation on this stream must be <a href="#inflateEnd">inflateEnd</a> to deallocate the decompression <a href="#state">state</a>. The use of <a href="#Z_FINISH">Z_FINISH</a> is never required, but can be used to inform <a href="#inflate">inflate</a> that a faster routine may be used for the single <a href="#inflate">inflate</a>() call. <p> If a preset dictionary is needed at this point (see <a href="#inflateSetDictionary">inflateSetDictionary</a> below), <a href="#inflate">inflate</a> sets strm-<a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of the dictionary chosen by the compressor and returns <a href="#Z_NEED_DICT">Z_NEED_DICT</a> ; otherwise it sets strm-> <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all output produced so far (that is, <a href="#total_out">total_out</a> bytes) and returns <a href="#Z_OK">Z_OK</a>, <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error code as described below. At the end of the stream, <a href="#inflate">inflate</a>() checks that its computed <a href="#adler32">adler32</a> checksum is equal to that saved by the compressor and returns <a href="#Z_STREAM_END">Z_STREAM_END</a> only if the checksum is correct. <p> <a href="#inflate">inflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input processed or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if the end of the compressed data has been reached and all uncompressed output has been produced, <a href="#Z_NEED_DICT">Z_NEED_DICT</a> if a preset dictionary is needed at this point, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was corrupted (input stream not conforming to the zlib format or incorrect <a href="#adler32">adler32</a> checksum), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent (for example if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <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 no progress is possible or if there was not enough room in the output buffer when <a href="#Z_FINISH">Z_FINISH</a> is used. In the <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> case, the application may then call <a href="#inflateSync">inflateSync</a> to look for a good compression block. <p><font color="Blue"><dt> int <a name="inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font><dd> All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output. <p> <a href="#inflateEnd">inflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a> was inconsistent. In the error case, <a href="#msg">msg</a> may be set but then points to a static string (which must not be deallocated).</dl><hr><a name="Advanced functions"><h2> Advanced functions </h2> The following functions are needed only in some special applications.<h3> Function list </h3><ul><li> int <a href="#deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm,<li> int <a href="#deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);<li> int <a href="#deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);<li> int <a href="#deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);<li> int <a href="#deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);<li> int <a href="#inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);<li> int <a href="#inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);<li> int <a href="#inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);<li> int <a href="#inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</ul><h3> Function description </h3><dl><font color="Blue"><dt> int <a name="deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int method, int windowBits, int memLevel, int strategy);</font><dd> This is another version of <a href="#deflateInit">deflateInit</a> with more compression options. The fields <a href="#next_in">next_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 method parameter is the compression method. It must be <a href="#Z_DEFLATED">Z_DEFLATED</a> in this version of the library.<p> The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage. The default value is 15 if <a href="#deflateInit">deflateInit</a> is used instead.<p> The memLevel parameter specifies how much memory should be allocated for the internal compression <a href="#state">state</a>. memLevel=1 uses minimum memory but is slow and reduces compression ratio ; memLevel=9 uses maximum memory for optimal speed. The default value is 8. See zconf.h for total memory usage as a function of windowBits and memLevel.<p> The strategy parameter is used to tune the compression algorithm. Use the value <a href="#Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> for normal data, <a href="#Z_FILTERED">Z_FILTERED</a> for data produced by a filter (or predictor), or <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> to force Huffman encoding only (no string match). Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to <a href="#compress">compress</a> them better. The effect of <a href="#Z_FILTERED">Z_FILTERED</a> is to force more Huffman coding and less string matching ; it is somewhat intermediate between Z_DEFAULT and <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a>. The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately.<p> <a href="#deflateInit2">deflateInit2</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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -