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

∥☆過路亽.° 提交于 2020-01-09 05:14:04

问题


How can I easily compress and decompress files using zlib?


回答1:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/5649030/how-can-i-easily-compress-and-decompress-files-using-zlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!