我正在使用 zlib 编写一个在多个线程中压缩数据的程序。所以我不能使用gzwrite。我正在使用 compress2()。
*dest_len = compressBound(LOG_BUFF_SZ);
err = compress2((Bytef*)compressed_buff->buff, dest_len, (Bytef*)b->buff, size, GZ_INT_COMPRESSION_LEVEL);
write(fd, compressed_buff->buff, compressed_buff->full);
但是当我尝试通过 gzip -d 解压缩文件时,我看到下一个输出:“不是 gzip 格式”。我究竟做错了什么?谢谢您的回答
compress()
and compress2()
压缩到zlib 格式 https://www.rfc-editor.org/rfc/rfc1950,不是gzip 格式 https://www.rfc-editor.org/rfc/rfc1952。您需要使用较低级别的函数才能选择 gzip 格式。那些是deflateInit2()
, deflate()
and deflateEnd()
。阅读文档zlib.h http://www.zlib.net/manual.html对于这些功能。之后,您还应该查看详细记录了它们的使用示例 http://www.zlib.net/zlib_how.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)