开发者

Decompress Gzip web streams in Qt

I found this class to make what the title states. But it always complain a segfault. Can somebody help me to debug it? Regards

   gzipDecompress(QByteArray &compressData)
        {

            //decompress GZIP data
            //strip header and trailer
              compressData.remove(0, 10);
              compressData.chop(12);

              const int buffersize = 16384;
              quint8 buffer[buffersize];

              z_stream cmpr_stream;
              cmpr_stream.next_in = (unsigned char *)compressData.data();
              cmpr_stream.avail_in = compressData.size();
              cmpr_stream.total_in = 0;

              cmpr_stream.next_out = buffer;
              cmpr_stream.avail_out = buffersize;
              cmpr_stream.total_out = 0;

              cmpr_stream.zalloc = Z_NULL;
              cmpr_stream.zalloc = Z_NULL;

              if( inflateInit2(&cmpr_stream, -8 ) != Z_OK) {
                      qDebug() << "cmpr_stream error!";
              }

                QByteArray uncompressed;

                do {
                    qDebug()<<"decompress................"<<uncompressed.size();
                        int status = inflate( &cmpr_stream, Z_SYNC_FLUSH );

                        if(status == Z_OK || status == Z_STREAM_END) {
                                uncompressed.append(QByteArray::fromRawData(
                                     (char *)buffer,
                                     buffersize - cmpr_stream.avail_out));
                                cmpr_stream.next_out开发者_StackOverflow社区 = buffer;

                                cmpr_stream.avail_out = buffersize;
                        } else {
                                 inflateEnd(&cmpr_stream);
                                }

                        if(status == Z_STREAM_END) {
                            inflateEnd(&cmpr_stream);
                            break;
                        }

                }while(cmpr_stream.avail_out == 0);

                return uncompressed;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜