Q:

Uncompressing files with Qt qUnCompress function

I read documentation and post about uncompressing ZIP files but I've additional questions. 
I need to uncompress zip file in Qt. That is XML file compressed with gzip. 
I know that qUnCompress can uncompressing zip files prepared with ZLIB and ZLIB has diffrent header than GZIP. 
As i read in documentation:

Note: If you want to use this function to uncompress external data that was compressed using zlib, you first need to prepend a four byte header to the byte array containing the data. The header must contain the expected length (in bytes) of the uncompressed data, expressed as an unsigned, big-endian, 32-bit integer.

Is that means that I have to put at the beginning only length (bigendian) and than compressed data ?
I did it but I have an error from qUncompress function: 

qUncompress: Z_DATA_ERROR: Input data is corrupted

A:

You need to write you own gUncompress() function using either zlib, or some other library, that implements the DEFLATE algorithm. I personally prefer miniz:
http://code.google.com/p/miniz/
Here's some code for you:
#include <stdexcept>

#include <QtCore>

#ifndef TINFL_HEADER_FILE_ONLY
# define TINFL_HEADER_FILE_ONLY
#endif // TINFL_HEADER_FILE_ONLY
extern "C" {
# include "tinfl.h"
}

#include "guncompress.hpp"

static tinfl_decompressor inflator;

static QByteArray result(TINFL_LZ_DICT_SIZE, 0);

//////////////////////////////////////////////////////////////////////////////
QByteArray gUncompress(QByteArray const& data)
{
  mz_uint8 const* inPtr(reinterpret_cast<mz_uint8 const*>(data.data()) + 10);

  tinfl_init(&inflator);

  size_t inAvail(data.size());
  size_t outTotal(0);

  tinfl_status ret;

  do
  {
    size_t inSize(inAvail);
    size_t outSize(result.size() - outTotal);

    ret = tinfl_decompress(&inflator,
      inPtr,
      &inSize,
      reinterpret_cast<mz_uint8*>(result.data()),
      reinterpret_cast<mz_uint8*>(result.data()) + outTotal,
      &outSize,
      0 
      );

    switch (ret)
    {
      case TINFL_STATUS_HAS_MORE_OUTPUT:
        inAvail -= inSize;
        inPtr += inSize;

        result.resize(2 * result.size());

      case TINFL_STATUS_DONE:
        outTotal += outSize;
        break;

      default:
        throw std::runtime_error("error decompressing gzipped content");
    }
  }
  while (TINFL_STATUS_DONE != ret);

  return QByteArray::fromRawData(result.data(), outTotal);
}

Also note that zip files and gzip files do not share the same format. Zip files need to be handled differently, as they contain a directory of files they contain.

