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
You need to write you own
gUncompress()function using eitherzlib, or some other library, that implements theDEFLATEalgorithm. I personally preferminiz:http://code.google.com/p/miniz/
Here’s some code for you:
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.