ZLib库使用

简单做了下Zlib库的测试

#include "zip/zlib.h"
#include 

using namespace std;


int main()
{
	unsigned char buff[2048] = { 0 };
	unsigned char compressBuff[2048] = { 0 };
	unsigned char unCompressBuff[2048] = { 0 };

	while (true)
	{
		::memset(buff, 0, sizeof(buff));
		::memset(compressBuff, 0, sizeof(compressBuff));
		::memset(unCompressBuff, 0, sizeof(unCompressBuff));
		unsigned long buffLen = 2048;
		unsigned long compressLen = 2048;
		unsigned long unCompressLen = 2048;
		cin >> buff;
		buffLen = strlen((const char*)buff);
		auto ret = compress2(compressBuff, &compressLen, buff, buffLen, Z_BEST_SPEED);
		cout << "ret:" << ret << ", [";
		for (auto i = 0; i < compressLen; i++)
		{
			printf("%02x", compressBuff[i]);
		}
		cout << "]" << endl;

		ret = uncompress2(unCompressBuff, &unCompressLen, compressBuff, &compressLen);
		cout << "ret:" << ret << ", [" << unCompressBuff << "]" << endl;
	}


	return 0;
}
hello
ret:0, [7801cb48cdc9c90700062c0215]
ret:0, [hello]
helloworld
ret:0, [7801cb48cdc9c92fcf2fca4901001736043d]
ret:0, [helloworld]
test
ret:0, [78012b492d2e0100045d01c1]
ret:0, [test]
he
ret:0, [7801cb480500013700ce]
ret:0, [he]
asdjakj
ret:0, [78014b2c4ec94accce02000b5f02d9]
ret:0, [asdjakj]
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
ret:0, [7801abaa221d0000910618c9]
ret:0, [zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]

你可能感兴趣的:(C++,Zlib)