如何使用zlib轻松压缩和解压缩文件?
解决方法:
对于减压:
char buf[1024*1024*16];
gzFile *fi = (gzFile *)gzopen("file.gz","rb");
gzrewind(fi);
while(!gzeof(fi))
{
int len = gzread(fi,buf,sizeof(buf));
//buf contains len bytes of decompressed data
}
gzclose(fi);
用于压缩
gzFile *fi = (gzFile *)gzopen("file.gz","wb");
gzwrite(fi,"my decompressed data",strlen("my decompressed data"));
gzclose(fi);