#include "stdafx.h"
#include "zlib.h"
#include <iostream>
#include <fstream>
using namespace std;
#pragma comment(lib,"zdll.lib")
size_t get_fsize(Byte*& buf_out, unsigned int all_size)
{
ifstream in("h:\\qt\\hello.zip", ios::binary);
size_t index = 0x00;
while(!in.eof())
{
char buf[1024] = {0x00};
in.read(buf, 1024);
size_t size = in.gcount();
if(size <= 0x00)
break;
memcpy(buf_out + index , buf, size);
index += size;
}
return index;
}
int _tmain(int argc, _TCHAR* argv[])
{
int err;
Byte * buf = new Byte[1024 * 1024];
unsigned long uncomprLen = 1024 * 1024;
Byte *compr = new Byte[1024 * 1024];
unsigned int all_size = 1024 * 1024;
unsigned int fsize = get_fsize(compr, all_size);
err = uncompress(buf, &uncomprLen, compr, fsize);
if (err != Z_OK)
{
cerr << "解压错误: " << err << endl;
}
std::ofstream ofile("c:\\hello",ios::binary);
ofile.write((char*)buf,uncomprLen);
ofile.close();
return 0;
}
注:zlib版本为1.2.8