我有一个用 PHP gzcompress($string) 写的压缩字符串
我需要在 QT 上用 C++ 阅读它。
非常感谢任何帮助!
最佳答案
您可以使用 qUncompress:http://doc.trolltech.com/4.6/qbytearray.html#qUncompress
请注意,您需要预先添加预期的未压缩长度。
示例代码(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);
未压缩的数据将在 aInUnCompBytes 中。 您需要阅读/了解压缩的 len 和未压缩的 len。 它没有经过测试,因为我现在的机器上没有 Qt。
最好的问候,
关于php - 如何在 QT/C++ 中解压缩在 PHP 中压缩的数据 (gzcompres),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2654030/