0
votes

I have a problem with decompressing some gzip data. I have an array with pointers to dynamically allocated char strings. Each element of this array is one part of the gzip file that I want to uncompress. The first thing which comes to my mind is to concatenate those strings to one, and then decompress data, but I want to avoid this method because of a lot of copying.

So the question is: Is there any way to decompress data divided into few parts, using zlib library ? I was trying to do it, but when I decompress the first part I get Z_DATA_ERROR - and it's normal, because the data is not complete. Is there any way to "wait" for the rest of data to decompress?

1
Have you seen this? hewgill.com/journal/entries/… You should be able to call inflate() multiple times with the chunks to decompress one by one....John Zwinck
yes, I don't have a problem to decompress gzip file when it is in one piece. I am only wondering what to do when I have it in few parts. I wanted to do it one by one, but when I am decompressing the first part I am getting Z_DATA_ERROR because it is not complete, hence it is not decompresseduser3131037
Check the advanced functions in the reference, there you will find the inflateBack function which uses callbacks to read and write data.Some programmer dude

1 Answers

1
votes

Yes. You can simply call inflate() successively with each of the strings in the appropriate order. for each call of inflate(), you can provide a different pointer and length for the compressed data. Each time, make sure that you first consume all of the uncompressed data generated and that avail_in is zero before moving on to the next chunk of input.

If you are getting a Z_DATA_ERROR that means that either you are not reassembling the original stream correctly, or that the original stream is not a gzip stream.

Note that to decompress a gzip stream, you need to initialize with inflateInit2() and set the parameters appropriately to request gzip decompression.