#include stdio.h>
! D/ g+ _9 s0 ~; A( i#include "zlib.h"
0 v c4 T4 T' ~0 Q; K# O+ Xint main()9 D: ?/ ~- g; r! s/ P- Y
{
a" \5 s+ q4 _. m- m //原始数据 W( S8 i. T4 z9 b5 q5 ?
const unsigned char strSrc[]="hello chinaavg!\\n\\
4 n" a: g2 T! c6 I; f9 HAVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试\\- s- R. G3 r' ^- F( {8 E9 j
www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\$ X" \4 L; r/ M4 _' u6 I: Q
www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\
$ B' F- z7 R- a/ qwww.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com";4 W7 [/ U) S: `+ D* o! e
unsigned char buf[1024]={0},strDst[1024]={0};
8 [" M2 n2 @$ l3 Y unsigned long srcLen=sizeof(strSrc),bufLen=sizeof(buf),dstLen=sizeof(strDst);: O& C8 P: H, N9 G7 e" g0 v+ \
printf("Src string:%s\\nLength:%d\\n",strSrc,srcLen);
4 a8 C3 W9 \$ a8 _9 D1 C //压缩8 H/ Z2 x e# J7 J" O
compress(buf,&bufLen,strSrc,srcLen);
/ {+ T! \% |/ l" ~9 u. z printf("\\nAfter Compressed Length:%d\\n",bufLen);; N K1 T- U2 S3 W& C! Q
printf("Compressed String:%s\\n",buf);2 [9 g& m, T$ c! \5 C. I
//解压缩
: Z" ?, W3 e4 \2 @3 N uncompress(strDst,&dstLen,buf,bufLen);5 `$ k) `2 ~( z
printf("\\nAfter UnCompressed Length:%d\\n",dstLen);& z1 k5 _0 Q* d% R+ a1 D. _; Q* a0 j
printf("UnCompressed String:%s\\n",strDst);
1 G7 W2 }+ p2 t4 ] return 0;- k$ o r2 f: x
} |