尝试使用zlib.h实用程序函数compress压缩数据,始终返回Z_BUF_ERROR

时间:2013-08-21 14:16:12

标签: c++ ubuntu-12.04 zlib compression

根据zlib手册,此错误表示“输出缓冲区空间不足”。下面是我非常基本的压缩程序。我还确认正在正确填充nUncompressedBuffer。另外你会注意到nCompressedBuffer比nUncompressedBuffer大得多,并且缓冲区大小的组合对我来说都没有用。请帮助:)

CDataBlock* CCompressionManager::Compress2(CDataBlock* pInBlock)
{
    U8     nCompressedBuffer[100000];
    U8     nUncompressedBuffer[1000];
    S8     status                 = 0;
    uLongf compressedBufferLength = 0;

    pInBlock->GetData()->GetData( nUncompressedBuffer, 1000 );

    status = compress2( nCompressedBuffer,
                       &compressedBufferLength,
                       nUncompressedBuffer,
                       pInBlock->GetData()->GetLength(),
                       Z_DEFAULT_COMPRESSION );

printf("status is: %i\n", status);
//this always results in -5 Z_BUF_ERROR


}

1 个答案:

答案 0 :(得分:0)

好吧,你应该告诉它输出缓冲区是0字节长。

- @PlasmaHH