// From qtsdk-2010.05/qt/src/network/access/qhttpnetworkreply_p.h
static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header
// gzip flag byte
#define HEAD_CRC 0x02 // bit 1 set: header CRC present
#define EXTRA_FIELD 0x04 // bit 2 set: extra field present
#define ORIG_NAME 0x08 // bit 3 set: original file name present
#define COMMENT 0x10 // bit 4 set: file comment present
#define RESERVED 0xE0 // bits 5..7: reserved
#define CHUNK 16384
// From qtsdk-2010.05/qt/src/network/access/qhttpnetworkreply.cpp
// && bool ClientParser::gzipCheckHeader(QByteArray &content, int &pos) same file
/// bool ClientParser::gzipCheckHeader(QByteArray &content, int &pos)
void ClientHandler::compressResponse(const QByteArray& uncompressed, QByteArray& deflated )
{
deflated = qCompress(uncompressed);
// eliminate qCompress size on first 4 bytes and 2 byte header
deflated = deflated.right(deflated.size() - 6);
// remove qCompress 4 byte footer
deflated = deflated.left(deflated.size() - 4);
header.resize(10);
header[0] = 0x1f; // gzip-magic[0]
header[1] = 0x8b; // gzip-magic[1]
header[2] = 0x08; // Compression method = DEFLATE
header[3] = 0x00; // Flags
header[4] = 0x00; // 4-7 is mtime
header[5] = 0x00;
header[6] = 0x00;
header[7] = 0x00;
header[8] = 0x00; // XFL
header[9] = 0x03; // OS=Unix
deflated.prepend(header);
quint32 crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, (const uchar*)uncompressed.data(), uncompressed.size());
footer.resize(8);
footer[3] = (crc & 0xff000000) >> 24;
footer[2] = (crc & 0x00ff0000) >> 16;
footer[1] = (crc & 0x0000ff00) >> 8;
footer[0] = (crc & 0x000000ff);
quint32 isize = uncompressed.size();
footer[7] = (isize & 0xff000000) >> 24;
footer[6] = (isize & 0x00ff0000) >> 16;
footer[5] = (isize & 0x0000ff00) >> 8;
footer[4] = (isize & 0x000000ff);
deflated.append(footer);
}
Bookmarks