这是我的c ++代码:
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QFile>
#include <QByteArray>
QByteArray UnZip (QString zipfilename)
{
QFile infile(zipfilename);
infile.open(QIODevice::ReadOnly);
//QByteArray uncompressedData = infile.readAll();
QByteArray uncompressedData = qUncompress(infile.readAll());
infile.close();
return uncompressedData;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//QString path = "/Users/davide/Desktop/fh8RkbUf";
QString path = "/Users/davide/Desktop/test";
QByteArray data = UnZip(path);
qDebug() << "message";
return a.exec();
}
返回qUncompress: Z_DATA_ERROR: Input data is corrupted
但是,数据应该是zlib压缩的,并且php的gzuncompress($data)
可以正常工作。
此外,cat file | uncompress
会返回错误。
代码php端是
$data = gzcompress($data, 6);
$success = file_put_contents($file, $data);