#include stdio.h>& d( S6 @2 M b3 Z
#include "zlib.h"
0 x, C# c) R: L" N! T' Iint main(); k1 S0 A: p+ @4 ]8 s
{
; i: ~: }' m# @0 _0 g. Y: o //原始数据
! `( S2 F, ?1 D3 G$ p7 Q const unsigned char strSrc[]="hello chinaavg!\\n\\
3 Y. k, O0 S! AAVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试\\
0 Y9 G4 |. T' Z8 \/ U3 g& ]www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\
: N9 t: n# V; l2 B. ~www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\
- T% z9 U0 }, B5 k Dwww.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com";8 i( `1 O6 n& o; v+ a3 L) t
unsigned char buf[1024]={0},strDst[1024]={0};
) W, u) R! j3 ~3 S; b unsigned long srcLen=sizeof(strSrc),bufLen=sizeof(buf),dstLen=sizeof(strDst);
. h( s1 S9 ]$ \ printf("Src string:%s\\nLength:%d\\n",strSrc,srcLen);& y% U9 y6 N7 ?1 y+ X8 I
//压缩
( o* v" [% N1 {1 H compress(buf,&bufLen,strSrc,srcLen);. O$ I' F* t% x, N+ }7 V
printf("\\nAfter Compressed Length:%d\\n",bufLen);
. l ^1 {: o) g printf("Compressed String:%s\\n",buf);
/ z2 q9 m& k. y# E, ^$ M9 c //解压缩
/ P5 T$ v& h& e n# t: s uncompress(strDst,&dstLen,buf,bufLen);1 P) A8 W/ u0 W( o4 [; ~ B1 v- z
printf("\\nAfter UnCompressed Length:%d\\n",dstLen);
* i* t$ E; p& v printf("UnCompressed String:%s\\n",strDst);" f7 s( P) K: f; V2 t! O( ~. E7 H
return 0;
o) {8 q0 O- N/ n# E0 Q8 l} |