#include stdio.h>
0 f4 S3 B7 G. J3 D) C+ \#include "zlib.h"5 Q6 ]& T+ L' C; ?
int main()5 Z4 [6 v# g! e$ V# O% W! w# }
{- J( q' }1 Y# O
//原始数据
# q7 Q0 }0 A) Y! } const unsigned char strSrc[]="hello chinaavg!\\n\\; _; [% \/ g W+ B# H: {# b" c! m
AVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试 AVG测试\\
4 _" ~% e7 p0 q3 Dwww.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\( N$ S8 Y4 T& U
www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com\\, A$ \) R" J1 }& [- P' u: h' B
www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com www.chinaavg.com";
. e2 S4 z# J( W5 q unsigned char buf[1024]={0},strDst[1024]={0};
4 P- g: D/ a3 @ unsigned long srcLen=sizeof(strSrc),bufLen=sizeof(buf),dstLen=sizeof(strDst);9 ~6 w* U( R# N" z' o$ c
printf("Src string:%s\\nLength:%d\\n",strSrc,srcLen);6 ?5 c* m0 N3 t: j; F+ t
//压缩
* G; V* W9 K- M$ m compress(buf,&bufLen,strSrc,srcLen);
: v2 j% W' A" M) T. ]) {7 T printf("\\nAfter Compressed Length:%d\\n",bufLen);$ C7 K1 Q! y6 F6 g1 c, ^
printf("Compressed String:%s\\n",buf);
9 V" O% w. Z7 d6 V' _9 ]: i/ m9 Z, A" ]7 { //解压缩9 d" [, R4 S+ @1 z+ g/ u
uncompress(strDst,&dstLen,buf,bufLen);
9 @) `+ {6 o2 T/ K* n L; \ printf("\\nAfter UnCompressed Length:%d\\n",dstLen);
" N. ?' [* i+ n8 E. b2 {' O5 x printf("UnCompressed String:%s\\n",strDst);7 A0 r1 [# y* j1 z. c: n
return 0;5 j' U5 P( i$ m) C/ S) x
} |