Hi
Is there a way that can uncompress a gzip compressed data?
qUncompress() method seems to be effective only for zlib ones i think. Will that work for gzip too (i think the header for both are different, so this method might not work)
Hi
Is there a way that can uncompress a gzip compressed data?
qUncompress() method seems to be effective only for zlib ones i think. Will that work for gzip too (i think the header for both are different, so this method might not work)
Probably you will need to embed gzip sources into your project:
http://www.gzip.org/#sources
The resources at the mentioned site seems to be in C. Is there any Qt resources available?
If you're already using libz, you can use its gz*() functions such as gzopen(), gzread() etc. to access gzip compressed files. If you are just accessing a gzip compressed data stream (i.e. not a file), you can use libz's deflate() functionality as inflate/deflate is the default compression method used in gzip files.
Hi
As mentioned i used the inflate function, but it is giving me Z_DATA_ERROR.
below is my code:
#define CHUNK 16384
FILE *source;
source = fopen("c:\\data\\response.txt", "r+");
if(!source)
; // Todo: error
z_stream stream;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.avail_in = 0;
stream.next_in = Z_NULL;
int ret = inflateInit(&stream);
// decompress until deflate stream ends or end of file
do{
stream.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source))
(void)inflateEnd(&stream);
if (stream.avail_in == 0)
return; // todo - error
stream.next_in = in;
do{
stream.avail_out = CHUNK;
stream.next_out = out;
int ret = inflate(&stream, Z_NO_FLUSH);
switch (ret)
{
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
{
(void)inflateEnd(&strm);
return ;
}
}
}while(stream.avail_out == 0);
}while(ret != Z_STREAM_END);
after reading the first 2 bytes, inflate returns -3. (for reference the gzip data stream starts like 1f8b0800000000000003c5d44f4fc2301400f0b3..... etc)
Is the set of 0x00 characters in the data stream causing the problem? can't gzip have any 0x00 bytes in it?
I am literally confused and desperate![]()
Make sure you're carefully observing the requirements to prime the buffers. I don't recall them exactly, but I'm pretty sure there are some.