程序功能:
1、将指定文件压缩成指定压缩包文件
2、从指定压缩文件读取内容。
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <zlib.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
// gzip格式
// (u16)MAGIC + (u8)DEFLATE + (u8)flag + (u32)time + (u8)deflate_flag + (u8)OS_CODE
int main(int argc, char *argv[])
{
if (argc < 3)
{
printf("usage : %s src_file dst_file\n", argv[1]);
return -1;
}
#if 0
string out;
//open .gz file
gzFile gzfp = gzopen(argv[1],"rb");
if(!gzfp)
{
return false;
}
//read and add it to out
unsigned char buf[1024];
int have;
while( (have = gzread(gzfp,buf,1024)) > 0)
{
out.append((const char*)buf,have);
}