Demo in short:
#include "zlib.h"
/* write buffer to gz file */
gzFile fp = gzopen("file.gz", "wb");
/* Writes the given number of uncompressed bytes into the compressed file.*/
gzwrite(fp, buffer, sizeof(buffer));
gzclose(fp);
/* read gz file into buffer */
gzFile fp = gzopen("file.gz", "rb");
/* read the given number of uncompressed bytes from the compressed file */
gzread(fp, buffer, sizeof(buffer));
/* or read a line */
gzgets(fp, buffer, sizeof(buffer));
gzclose(fp);
Use option "-lz" to link with zlib library.
Read more:
http://www.zlib.net/manual.html
没有评论:
发表评论