QByteArray src=iob.value().toByteArray();
unsigned long len_compress;
unsigned long len_uncompress=MaxBufferSize;
unsigned char *buffer_compress = new unsigned char[MaxBufferSize];
unsigned char *buffer_uncompress = new unsigned char[MaxBufferSize];
//压缩函数
compress(buffer_compress,&len_compress,(Bytef*)src.data(), src.length());
//解压
uncompress(buffer_uncompress,&len_uncompress,(Bytef*)buffer_compress,len_compress);
unsigned char *转回QBytearrary
QByteArray uncompressba=QByteArray::fromRawData((char*)buffer_uncompress,len_uncompress);
一般解压压缩就是上述步骤 我自己项目需求是要压缩完写道文件里 读取得时候读起来再解压
需要记录数据得大小和 压缩后得数据大小
unsigned char *buffer_compress2 = new unsigned char[MaxBufferSize];
// 压缩数据转回QByteArrary
// unsigned char *转回QBytearrary
QByteArray compressba=QByteArray::fromRawData(( char *)buffer_compress,len_compress);//xml
memcpy(buffer_compress2,compressba.data(),compressba.length());
uncompress(buffer_uncompress,&len_uncompress,(Bytef*)buffer_compress2,len_compress);
//解压后转会QByteArrary 得到最初得数据
QByteArray bytearrary=QByteArray::fromRawData((char *)buffer_uncompress,MaxBufferSize);// ok
重点是一定要知道压缩前的数据大小 和 压缩后的数据的大小