VC使用Zlib对内存流进行压缩与解压缩

//在工程根目录放入文件
zlib.h
zlib.lib
zconf.h
(这3个文件,zlib官方下载编译成的,觉得麻烦向我索要)

 

//加载Zlib相应的函数以及库
#include "zlib.h"
#pragma comment(lib,"zlib.lib")

对于已知数组b 以及数组长度Count

 

//压缩
BYTE *com=new BYTE[Count];
unsigned long mSize;
compress(com,&mSize,b,Count);

 

//解压缩
unsigned long nSize;
BYTE *target=new BYTE[Count];
uncompress(target,&nSize,com,mSize);

 

//使用完释放指针
delete [Count] target;

 

 

 

posted @ 2010-08-15 21:04  huhu0013  阅读(2832)  评论(0编辑  收藏  举报