10 QByteArray HttpGZipCompression::compressData(
const QByteArray &data) {
11 return header() + compress(data) + footer(data);
15 QByteArray HttpGZipCompression::header() {
16 return QByteArray::fromHex(
"1f8b080000000000000b");
20 QByteArray HttpGZipCompression::compress(
const QByteArray &sourceData) {
21 QByteArray compressedData = qCompress(sourceData);
22 compressedData.remove(0, 6);
23 compressedData.chop(4);
24 return compressedData;
28 QByteArray HttpGZipCompression::footer(
const QByteArray &sourceData) {
30 QDataStream footerStream(&footer, QIODevice::WriteOnly);
31 footerStream.setByteOrder(QDataStream::LittleEndian);
32 footerStream << crc32(sourceData) << quint32(sourceData.size());
37 quint32 HttpGZipCompression::updateCRC32(
unsigned char ch, quint32 crc) {
38 return (crc_32_tab[((crc) ^ ((quint32)ch)) & 0xff] ^ ((crc) >> 8));
42 quint32 HttpGZipCompression::crc32(
const QByteArray& data) {
43 quint32 crc = 0xFFFFFFFFL;
44 for (
int i=0; i<data.size(); i++) {
45 crc = updateCRC32(data[i], crc);