tags:

views:

103

answers:

2

I have a compressed string written by PHP gzcompress($string)

I need to read it with C++ on QT.

Any help is very appreciated!

+1  A: 

Analog for PHP functions gzcompress/gzuncompress is ZLIB. It is available in python and c++ - there you can find functions for decompression.

serge
+1  A: 

You can use qUncompress: http://doc.trolltech.com/4.6/qbytearray.html#qUncompress
Please note that you need to prepend the expected uncompressed length.

Sample code (in C++):

QByteArray aInCompBytes;
QByteArray aInUnCompBytes;
QByteArray aInCompBytesPlusLen;

int currentCompressedLen = <<read_this>>;
int currentUnCompressedLen = <<read_this>>;

aInCompBytes.resize(currentCompressedLen);

char slideStr[currentCompressedLen];
int slideByteRead = in.readRawData(slideStr, currentCompressedLen);

aInCompBytes = QByteArray(slideStr, slideByteRead);
aInCompBytesPlusLen = aInCompBytes;
aInCompBytesPlusLen.prepend(QByteArray::number(currentUnCompressedLen));
aInUnCompBytes.resize(currentUnCompressedLen);
aInUnCompBytes = qUncompress(aInCompBytesPlusLen);

The uncompressed data will be in aInUnCompBytes. You need to read/know the compressed len and uncompressed len. It wasn't tested, as I don't have Qt in my machine right now.

Best regards, T.

Thiago Silveira
thats right, on C++
Regof