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

s669pengwei 2012-01-18 11:28:12
求知情人帮忙
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
aijiumei 2012-01-31
  • 打赏
  • 举报
回复

/*
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. The
00488 fields next_in, zalloc, zfree and opaque must be initialized before by
00489 the caller.
00490
00491 The method parameter is the compression method. It must be Z_DEFLATED in
00492 this version of the library.
00493
00494 The windowBits parameter is the base two logarithm of the window size
00495 (the size of the history buffer). It should be in the range 8..15 for this
00496 version of the library. Larger values of this parameter result in better
00497 compression at the expense of memory usage. The default value is 15 if
00498 deflateInit is used instead.
00499
00500 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
00501 determines the window size. deflate() will then generate raw deflate data
00502 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. Add
00505 16 to windowBits to write a simple gzip header and trailer around the
00506 compressed data instead of a zlib wrapper. The gzip header will have no
00507 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 a
00509 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 allocated
00512 for the internal compression state. memLevel=1 uses minimum memory but
00513 is slow and reduces compression ratio; memLevel=9 uses maximum memory
00514 for optimal speed. The default value is 8. See zconf.h for total memory
00515 usage as a function of windowBits and memLevel.
00516
00517 The strategy parameter is used to tune the compression algorithm. Use the
00518 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
00519 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
00520 string match), or Z_RLE to limit match distances to one (run-length
00521 encoding). Filtered data consists mostly of small values with a somewhat
00522 random distribution. In this case, the compression algorithm is tuned to
00523 compress them better. The effect of Z_FILTERED is to force more Huffman
00524 coding and less string matching; it is somewhat intermediate between
00525 Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
00526 Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
00527 parameter only affects the compression ratio but not the correctness of the
00528 compressed output even if it is not set appropriately. Z_FIXED prevents the
00529 use of dynamic Huffman codes, allowing for a simpler decoder for special
00530 applications.
00531
00532 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
00533 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
00534 method). msg is set to null if there is no error message. deflateInit2 does
00535 not perform any compression: this will be done by deflate().
00536 */
s669pengwei 2012-01-18
  • 打赏
  • 举报
回复
我调用的是zlib里面的compress函数压缩,从内存在内存的,最后经过打包以后存到文件中,想再用linux自带的工具解压,不知道用什么可以
arfi 2012-01-18
  • 打赏
  • 举报
回复
zip?
试一下 unzip
s669pengwei 2012-01-18
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 smallsmallsmallsmall 的回复:]

那你为什么不用gzip压缩,而选择自己实现呢?对压缩有什么特定的需求吗?

如果没有特定需求,就用system()直接调用gzip好了。
[/Quote]
要是用system,是不是只能对文件进行压缩?我希望是对内存中的buffer进行压缩,输出也为内存中的。
  • 打赏
  • 举报
回复
那你为什么不用gzip压缩,而选择自己实现呢?对压缩有什么特定的需求吗?

如果没有特定需求,就用system()直接调用gzip好了。
s669pengwei 2012-01-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 smallsmallsmallsmall 的回复:]

如果只是打算解压,不限定必须使用gzip, 就自己用zlib库里的uncompress写个解压的小工具好了。
[/Quote]
本来我也是这样想的,但是不通用,要是利用linux自带的通用工具就能解压就最好了
  • 打赏
  • 举报
回复
如果只是打算解压,不限定必须使用gzip, 就自己用zlib库里的uncompress写个解压的小工具好了。

s669pengwei 2012-01-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhao4zhong1 的回复:]

内存里的zip数据和磁盘上的zip文件相比少了zip文件头信息吧。
[/Quote]
那怎么加上呢?
赵4老师 2012-01-18
  • 打赏
  • 举报
回复
内存里的zip数据和磁盘上的zip文件相比少了zip文件头信息吧。

64,678

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧