mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2025-07-27 09:14:25 +02:00
Initial version
This commit is contained in:
35
src/gzip.cpp
Normal file
35
src/gzip.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <QtEndian>
|
||||
#include <QDebug>
|
||||
#include <zlib.h>
|
||||
#include "gzip.h"
|
||||
|
||||
|
||||
QByteArray Gzip::uncompress(const QByteArray &data)
|
||||
{
|
||||
QByteArray uba;
|
||||
z_stream stream;
|
||||
|
||||
quint32 *size = (quint32*)(data.constData() + data.size() - sizeof(quint32));
|
||||
uba.resize(qFromLittleEndian(*size));
|
||||
|
||||
stream.zalloc = Z_NULL;
|
||||
stream.zfree = Z_NULL;
|
||||
stream.opaque = Z_NULL;
|
||||
|
||||
stream.next_in = (Bytef*)data.constData();
|
||||
stream.avail_in = data.size();
|
||||
stream.next_out = (Bytef*)uba.data();
|
||||
stream.avail_out = uba.size();
|
||||
|
||||
if (inflateInit2(&stream, MAX_WBITS + 16) != Z_OK)
|
||||
return uba;
|
||||
|
||||
if (inflate(&stream, Z_NO_FLUSH) != Z_STREAM_END) {
|
||||
qCritical() << "Invalid gzip data";
|
||||
uba = QByteArray();
|
||||
}
|
||||
|
||||
inflateEnd(&stream);
|
||||
|
||||
return uba;
|
||||
}
|
Reference in New Issue
Block a user