开发者

zlib inflate in memory

I have a small buffer with some data (ca. 35'000 bytes). No i would like to inflate my buffer with zlib. The buffer is named "pos_in_mem" (void *) and the length of my buffer is len (int *).

I always get a -3 (Z_DATA_ERROR) on that part of code:

int ret;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];

/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK) {
    printf("zlib init failed");
}
strm.avail_in = *len; // this is my buffer length
strm.next_in = pos_in_mem; // this is my buffer

strm.avail_out = CHUNK;
strm.next_out = out;

//ret = deflate(&strm, flush);
ret = inflate(&strm, Z_NO_FLUSH); // 开发者_如何转开发here i always get a -3 Z_DATA_ERROR
printf("%d", strm.avail_out);
(void)inflateEnd(&strm);

any ideas?

Thanks


You probably mistook inflate with deflate.

inflate - inflation, rise of volume, decompress

deflate - deflation, decrease of volume, compress

Good deflate/inflate examples on zlib web page.


Probably your data is not in the expected format (raw?)

You may try inflateInit2(&strm, X):

  • X = -15 to do a raw inflate.
  • X = 15 + 32 to do a gzip/zlib auto format decoding.
  • X = 15 would do just the same as before.

Other than that it is difficult to say without seeing the deflate code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜