#include stdio.h>
~& Z/ l7 x" q- r+ N1 I#include "zlib.h"- w1 j) K, d; N) o5 j2 a. ^
int main()4 o8 r! ^0 ~, c. N# T) d1 W% j
{
% H2 b) w9 O6 ] //原始数据! i3 s! D5 m+ z# @- ]
const unsigned char strSrc[]="hello chinaavg!\\n\\
8 P1 p, g" h5 e; gAVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试\\! B1 X0 c1 T( Q1 p1 X
www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\
9 ]% e; r- h S) S4 m. Jwww.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\
* }, ]% ^5 W* G: _ `www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com";
$ x# f/ d, B$ X5 K1 h" l; D unsigned char buf[1024]={0},strDst[1024]={0};
' d6 }/ ^( O' S* l unsigned long srcLen=sizeof(strSrc),bufLen=sizeof(buf),dstLen=sizeof(strDst);
5 ~7 B+ w+ X1 o% G/ N1 U, C printf("Src string:%s\\nLength:%d\\n",strSrc,srcLen);, K: l" J4 I! `+ u
//压缩5 {! J& {6 U- v+ ^, s, O* Y
compress(buf,&bufLen,strSrc,srcLen);) |" h0 ]; r6 a5 q! V
printf("\\nAfter Compressed Length:%d\\n",bufLen);
( D. b8 T+ v) p printf("Compressed String:%s\\n",buf);! d2 D" x; I$ [/ [6 [1 B3 Q+ {
//解压缩
0 t; R% K% E9 E: { uncompress(strDst,&dstLen,buf,bufLen);
# K7 E+ s7 @/ p" \ W" b printf("\\nAfter UnCompressed Length:%d\\n",dstLen);
% N* P/ O* u8 g( d3 Z3 T- C printf("UnCompressed String:%s\\n",strDst);
' p' {! [* z$ K3 b" q return 0;
# n d# G1 p7 p; A} |