开发者

How can I easily compress and decompress files using zlib? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 5 years ago.

Improve this que开发者_StackOverflow社区stion

How can I easily compress and decompress files using zlib?


For decompression:

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);

For compression

gzFile *fi = (gzFile *)gzopen("file.gz","wb");
gzwrite(fi,"my decompressed data",strlen("my decompressed data"));
gzclose(fi);


Please read through this. The information is already available here:
That is the first link that shows up even on google.


If you can use boost, I would recommend the boost iostreams API. See the boost iostreams tutorial. It has support for GZIP and BZIP2 compressors and decompressors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜