zlib中 compress() 返回 Z_BUF_ERROR的有关问题
zlib中 compress() 返回 Z_BUF_ERROR的问题
zlib中 compress() 返回 Z_BUF_ERROR (-5) :表示没有足够的输出缓冲区
返回 Z_MEM_ERROR (-4) : 表示没有足够的内存
返回 Z_OK (0) :成功!
我的程序如下:为什么老是出现 返回 -5 的情况呢?! %>_<%
buf[MAX_LEN]; 是我要压缩的数据,这个是没有问题的。
------解决方案--------------------
ret = compress(temp, &nzdata, buf, MAX_LEN);
====>
nzdata=MAX_LEN;
ret = compress(buf, &nzdata, temp, MAX_LEN);
------解决方案--------------------
收到数据是否完全?传个uncompress的长度是否是压缩后的数据长度?
------解决方案--------------------
char* srcBuf;
int srcLen;
int dstLen = 4*srcLen; //设为4倍一般就够了,
char* dstBuf = malloc( dstLen );
uncompress(dstBuf, &dstLen,srcBuf, srcLen);
zlib中 compress() 返回 Z_BUF_ERROR (-5) :表示没有足够的输出缓冲区
返回 Z_MEM_ERROR (-4) : 表示没有足够的内存
返回 Z_OK (0) :成功!
我的程序如下:为什么老是出现 返回 -5 的情况呢?! %>_<%
buf[MAX_LEN]; 是我要压缩的数据,这个是没有问题的。
unsigned long nzdata = 0;
unsigned char *temp;
temp = (unsigned char *)malloc(sizeof(char) * MAX_LEN);
memset(temp, 0, MAX_LEN);
int ret = 1;
ret = compress(temp, &nzdata, buf, MAX_LEN);
if(0 == ret)
{
printf("ok \n");
memset(buf, 0, MAX_LEN);
memcpy(buf, temp, nzdata);
free(temp);
printf("compress success\n");
}
else
{
// return -5: 输出缓冲区不够大
//return -4:没有足够的内存
free(temp);
printf("failed ret = %d \n", ret);
}
------解决方案--------------------
ret = compress(temp, &nzdata, buf, MAX_LEN);
====>
nzdata=MAX_LEN;
ret = compress(buf, &nzdata, temp, MAX_LEN);
------解决方案--------------------
收到数据是否完全?传个uncompress的长度是否是压缩后的数据长度?
------解决方案--------------------
char* srcBuf;
int srcLen;
int dstLen = 4*srcLen; //设为4倍一般就够了,
char* dstBuf = malloc( dstLen );
uncompress(dstBuf, &dstLen,srcBuf, srcLen);