quantass
January 27th, 2003, 11:08 PM
I just cant get the following code to work. First off the ZLIB compressor isnt compressing/uncompressing correctly (the src is originally 680kb, compressed = 78kb, uncompressed = 80kb) and many times over the statement: inp.open("d:\\Test20.zip", ios::binary); in the "uncompress area" isnt able to open the file for some reason setting "inp" to 0. What am i doing wrong within the following code?
The zlib header, libz.lib, and zlib.dll are available.
---
// ZLIB.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "zlib.h"
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
char *des, *src;
unsigned long desLen, tdesLen, srcLen, rlen;
std::ifstream inp;
std::ofstream oup;
/////////////////////////////////////////
// Compress Test20.exe to Test20.zip
/////////////////////////////////////////
inp.open("d:\\Test20.exe", ios::binary);
oup.open("d:\\Test20.zip", ios::binary);
srcLen=3000;
desLen=tdesLen=srcLen*1.001+12;
src=new char[srcLen];
des=new char[desLen];
inp.read(src,srcLen);
rlen=inp.gcount();
while(rlen)
{
compress2((Bytef *) des,&tdesLen,(Bytef *)src,rlen,2);
oup.write(des,tdesLen);
tdesLen=desLen;
inp.read(src,srcLen);
rlen=inp.gcount();
}
oup.close();
inp.close();
/////////////////////////////////////////
// Uncompress Test20.zip to Test20B.exe
/////////////////////////////////////////
inp.open("d:\\Test20.zip", ios::binary);
oup.open("d:\\Test20B.exe", ios::binary);
srcLen=3000;
desLen=tdesLen=srcLen*1.001+12;
inp.read(src,srcLen);
rlen=inp.gcount();
while(rlen)
{
uncompress((Bytef *) des,&tdesLen,(Bytef *)src,rlen);
oup.write(des,tdesLen);
tdesLen=desLen;
inp.read(src,srcLen);
rlen=inp.gcount();
}
oup.close();
inp.close();
return 0;
}
---
The zlib header, libz.lib, and zlib.dll are available.
---
// ZLIB.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "zlib.h"
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
char *des, *src;
unsigned long desLen, tdesLen, srcLen, rlen;
std::ifstream inp;
std::ofstream oup;
/////////////////////////////////////////
// Compress Test20.exe to Test20.zip
/////////////////////////////////////////
inp.open("d:\\Test20.exe", ios::binary);
oup.open("d:\\Test20.zip", ios::binary);
srcLen=3000;
desLen=tdesLen=srcLen*1.001+12;
src=new char[srcLen];
des=new char[desLen];
inp.read(src,srcLen);
rlen=inp.gcount();
while(rlen)
{
compress2((Bytef *) des,&tdesLen,(Bytef *)src,rlen,2);
oup.write(des,tdesLen);
tdesLen=desLen;
inp.read(src,srcLen);
rlen=inp.gcount();
}
oup.close();
inp.close();
/////////////////////////////////////////
// Uncompress Test20.zip to Test20B.exe
/////////////////////////////////////////
inp.open("d:\\Test20.zip", ios::binary);
oup.open("d:\\Test20B.exe", ios::binary);
srcLen=3000;
desLen=tdesLen=srcLen*1.001+12;
inp.read(src,srcLen);
rlen=inp.gcount();
while(rlen)
{
uncompress((Bytef *) des,&tdesLen,(Bytef *)src,rlen);
oup.write(des,tdesLen);
tdesLen=desLen;
inp.read(src,srcLen);
rlen=inp.gcount();
}
oup.close();
inp.close();
return 0;
}
---