关于ZLib的compress和uncompress,请教高手.

csersoft 2012-05-15 07:08:14
我用uncompress解压一个2进制的数组(UnByte),解压的没有问题,
问题是我把这个数组(UnByte)再用compress压缩回去,得到(ReComp)数组,
发现(ReComp)数组和(UnByte)数组不一样,起先还以为是压缩比的问题,
但是再把(ReComp)解压就出问题了.缓冲区有多大,返回的数组就有多大.请问这是什么情况?
我使用VB开发的,使用zlib.dll(1.13版)的没出现DLL调用约定的问题,
使用zlib.dll(1.23版)就出问题了,提示DLL调用约定错误,我后来下载了两个版本的源码.
发现DLL调用约定是一样的.没有什么问题.
...全文
276 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
geansea 2012-05-16
  • 打赏
  • 举报
回复
1、zlib可以指定压缩等级,在compress2里面提供了可控参数。
2、uncompress函数说明如下:
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total size
of the destination buffer, which must be large enough to hold the entire
uncompressed data. (The size of the uncompressed data must have been saved
previously by the compressor and transmitted to the decompressor by some
mechanism outside the scope of this compression library.) Upon exit, destLen
is the actual size of the uncompressed buffer.

uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
*/
有没有保证destLen足够大,并且检查返回值?

33,010

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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