giusepped
25th October 2011, 18:28
I use zlib to decompress gzip data from http responses.
Sometimes it does work.
I have this piece of code (buffers is a a QHash of QByteArray to make buffering):
....
buffers.value(host)->append(data);
qDebug()<<"SOCKET FLUSH-----------------"<<
proxySocket->property("flush")<<
proxySocket->property("current-length")<<
proxySocket->property("length")<<buffers<<
buffers.value(host)->isEmpty();
// did we buffer?
if (!buffers.value(host)->isEmpty())
{
content = QByteArray(buffers.value(host)->data());
qDebug()<<"FLUSHED BUFFER-------"<<content;
}
compressed = decompress(content);
In the output I have:
SOCKET FLUSH----------------- QVariant(, ) QVariant(int, 2262) QVariant(int, 2262) QHash(("", 0x47a68c0)
but the size of compressed is 0! How is it possible? I have 2262 byte in content, why the decompression does not work? Also if I print the size of content at the end of the code, it is lower than the size of the buffer, e.g. 2262
Added after 8 minutes:
First, I found that data() is not the correct way to pass the data, because data() returns a char*, a pointer.
content = QByteArray(*buffers.value(host));
This is right.
Sometimes it does work.
I have this piece of code (buffers is a a QHash of QByteArray to make buffering):
....
buffers.value(host)->append(data);
qDebug()<<"SOCKET FLUSH-----------------"<<
proxySocket->property("flush")<<
proxySocket->property("current-length")<<
proxySocket->property("length")<<buffers<<
buffers.value(host)->isEmpty();
// did we buffer?
if (!buffers.value(host)->isEmpty())
{
content = QByteArray(buffers.value(host)->data());
qDebug()<<"FLUSHED BUFFER-------"<<content;
}
compressed = decompress(content);
In the output I have:
SOCKET FLUSH----------------- QVariant(, ) QVariant(int, 2262) QVariant(int, 2262) QHash(("", 0x47a68c0)
but the size of compressed is 0! How is it possible? I have 2262 byte in content, why the decompression does not work? Also if I print the size of content at the end of the code, it is lower than the size of the buffer, e.g. 2262
Added after 8 minutes:
First, I found that data() is not the correct way to pass the data, because data() returns a char*, a pointer.
content = QByteArray(*buffers.value(host));
This is right.