这个是测试程序。。。来自网上。。
不过对于新版本的zlib有一个错误,偶修改了。
#include <cstring>
#include <cstdlib>
#include <iostream>
#include "zlib.h" //depence by zconf.h
//将zlib/win32/makefile.gcc拷到zlib目录中。
//执行MinGW环境变量批处理。
//执行mingw32-make -fMakefile.gcc 既可生成静态库,动态库对应的文件。可以参考命令行生成动态库的方法。
//可思考,如果不使用gzip?生成最小的zlib?
//1.2.7版本已经将vc6工程移出old目录,win32/目录下已经有makefile了。vc2008,2010直接支持编译。
//contrib\minizip中包含了操作zip文件的API包装示例。
using namespace std;
int main(int argc, char* argv[])
{
int err = 0;
Byte compr[200] = {0}, uncompr[200] = {0}; // big enough
uLong comprLen = 0, uncomprLen = 0;
const char* hello = "12345678901234567890123456789012345678901234567890";
uLong len = strlen(hello) + 1;
comprLen = sizeof(compr) / sizeof(compr[0]);
err = compress(compr, &comprLen, (const Bytef*)hello, len);
if (err != Z_OK)
{
cerr << "compess error: " << err << '\n';
exit(1);
}
cout << "orignal size: " << len
<< " , compressed size : " << comprLen << '\n';
cout << "compress string is:" << compr << endl;
strcpy((char*)uncompr, "garbage");
uncomprLen = 200; //here must be uncompress array size ,if 0 , will return -5 error!
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
if (err != Z_OK)
{
cerr << "uncompess error: " << err << '\n';
exit(1);
}
cout << "orignal size: " << len
<< " , uncompressed size : " << uncomprLen << '\n';
if (strcmp((char*)uncompr, hello))
{
cerr << "BAD uncompress!!!\n";
exit(1);
}
else
{
cout << "uncompress() succeed: \n" << (char*)uncompr;
}
}