首页 > 代码库 > gzip demo
gzip demo
#include <stdio.h> #include <zlib.h> // Demo int decompress_file(char *infilename, char *outfilename) { int num_read = 0; char buffer[128]; gzFile infile = gzopen(infilename, "rb"); FILE *outfile = fopen(outfilename, "wb"); if (!infile || !outfile) { return -1; } while ((num_read = gzread(infile, buffer, sizeof(buffer))) > 0) { fwrite(buffer, 1, num_read, outfile); } gzclose(infile); fclose(outfile); } int compress_file(char *infilename, char *outfilename) { int num_read = 0; char inbuffer[128]; FILE *infile = fopen(infilename, "rb"); gzFile outfile = gzopen(outfilename, "wb"); if (!infile || !outfile) { return -1; } while ((num_read = fread(inbuffer, 1, sizeof(inbuffer), infile)) > 0) { total_read += num_read; gzwrite(outfile, inbuffer, num_read); } fclose(infile); gzclose(outfile); } int main(int argc, char **argv) { compress_file(argv[1],argv[2]); decompress_file(argv[2],argv[3]); }
本文出自 “一路风景” 博客,请务必保留此出处http://which.blog.51cto.com/7179876/1602544
gzip demo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。