首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

zlib 压缩,为什么不能用gzip解压?解决思路

2012-02-06 
zlib 压缩,为什么不能用gzip解压?求知情人帮忙[解决办法]C/C++ code/*00480 ZEXTERN int ZEXPORT deflateI

zlib 压缩,为什么不能用gzip解压?
求知情人帮忙

[解决办法]

C/C++ code
/*00480 ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,00481                                      int  level,00482                                      int  method,00483                                      int  windowBits,00484                                      int  memLevel,00485                                      int  strategy));00486 00487      This is another version of deflateInit with more compression options. The00488    fields next_in, zalloc, zfree and opaque must be initialized before by00489    the caller.00490 00491      The method parameter is the compression method. It must be Z_DEFLATED in00492    this version of the library.00493 00494      The windowBits parameter is the base two logarithm of the window size00495    (the size of the history buffer). It should be in the range 8..15 for this00496    version of the library. Larger values of this parameter result in better00497    compression at the expense of memory usage. The default value is 15 if00498    deflateInit is used instead.00499 00500      windowBits can also be -8..-15 for raw deflate. In this case, -windowBits00501    determines the window size. deflate() will then generate raw deflate data00502    with no zlib header or trailer, and will not compute an adler32 check value.00503 00504      windowBits can also be greater than 15 for optional gzip encoding. Add00505    16 to windowBits to write a simple gzip header and trailer around the00506    compressed data instead of a zlib wrapper. The gzip header will have no00507    file name, no extra data, no comment, no modification time (set to zero),00508    no header crc, and the operating system will be set to 255 (unknown).  If a00509    gzip stream is being written, strm->adler is a crc32 instead of an adler32.00510 00511      The memLevel parameter specifies how much memory should be allocated00512    for the internal compression state. memLevel=1 uses minimum memory but00513    is slow and reduces compression ratio; memLevel=9 uses maximum memory00514    for optimal speed. The default value is 8. See zconf.h for total memory00515    usage as a function of windowBits and memLevel.00516 00517      The strategy parameter is used to tune the compression algorithm. Use the00518    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a00519    filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no00520    string match), or Z_RLE to limit match distances to one (run-length00521    encoding). Filtered data consists mostly of small values with a somewhat00522    random distribution. In this case, the compression algorithm is tuned to00523    compress them better. The effect of Z_FILTERED is to force more Huffman00524    coding and less string matching; it is somewhat intermediate between00525    Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as00526    Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy00527    parameter only affects the compression ratio but not the correctness of the00528    compressed output even if it is not set appropriately.  Z_FIXED prevents the00529    use of dynamic Huffman codes, allowing for a simpler decoder for special00530    applications.00531 00532       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough00533    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid00534    method). msg is set to null if there is no error message.  deflateInit2 does00535    not perform any compression: this will be done by deflate().00536 */ 

热点排行