×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    16

    Unhappy gzip uncompression in qt

    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)

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: gzip uncompression in qt

    Probably you will need to embed gzip sources into your project:
    http://www.gzip.org/#sources

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    16

    Re: gzip uncompression in qt

    The resources at the mentioned site seems to be in C. Is there any Qt resources available?

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: gzip uncompression in qt

    Quote Originally Posted by NishaElsa View Post
    The resources at the mentioned site seems to be in C.
    Yes, it shouldn't be a problem.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Location
    Oulu, Finland
    Posts
    1,122

    Re: gzip uncompression in qt

    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.

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    16

    Re: gzip uncompression in qt

    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

  7. #7
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: gzip uncompression in qt

    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.

Similar Threads

  1. Qt for Symbian development resources
    By liuxg in forum [Archived] Qt General ( Qt技术)
    Replies: 55
    Last Post: 2011-01-26, 04:06
  2. automatic rotate screen on meamo
    By fily_love in forum Nokia N9
    Replies: 27
    Last Post: 2010-04-06, 08:37
  3. gsreamer-0.10-plugins-good+Phonon
    By niqt in forum Nokia N9
    Replies: 10
    Last Post: 2010-03-05, 09:56
  4. kinetic scrolling
    By stalep in forum Nokia N9
    Replies: 10
    Last Post: 2009-12-08, 12:41
  5. Senior QT Client Developer (Dublin, Ireland)
    By marynyc in forum News and Announcements
    Replies: 0
    Last Post: 2009-06-02, 18:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •