1
char buffer[12] = {"Testing! 12"};
unsigned long compressedSize;
char* compressed = compress(buffer, 12, &compressedSize);
...
char* compress(char* buffer, unsigned long size, unsigned long* compressedSize)
{
Bytef* inBuffer = reinterpret_cast<Bytef*>(buffer);
uLong inSize = static_cast<uLong>(size);
Bytef* outBuffer = 0;
uLong outBufferSize = compressBound(inSize);
int error = compress2(outBuffer, &outBufferSize, inBuffer, inSize, 6);
if(error != Z_OK)
{
switch(error)
{
case Z_MEM_ERROR:
std::cerr << "Memory error!" << std::endl;
break;
case Z_BUF_ERROR:
std::cerr << "Buffer error!" << std::endl;
break;
default:
std::cerr << "Unknown error: " << error << std::endl;
break;
}
return 0;
}
*compressedSize = static_cast<unsigned long>(outBufferSize);
return reinterpret_cast<char*>(outBuffer);
}
我打'未知的錯誤:-2'原來是ZLIB_STREAM_ERROR。我無法弄清楚這個問題。所有的變量似乎都是正確的。zlib compress2正在返回Z_STREAM_ERROR
它在說什麼http://zlib.net/manual.html#Utility有關。 – Jookia 2011-02-05 21:05:04