I've included the code for the subroutine I'm using at the end of the
message.
When I create Gzip and Gunzip objects and don't use any piping or sinks or
sources, everything works fine. I can load in a file and zip it, save it,
reload it, unzip it, and save the new version and it'll be the same as the
first file - and with no errors thrown along the way. I tested this cycle
in several ways while experimenting and had no problems and not one error
was thrown.
Then I experimented to do the same thing with piping - using a FileSource
and a FileSink. When I do that, some file are okay, but on some files, I
get a message, "Gunzip: header decoding error." But this happens only on
some files.
I did more experimenting and my code does this:
1) Use FileSource -> GZip -> FileSink to deflate the data and produce a
.zip file (I'm using .zip as a label, I know it's not actually a .zip
file.)
2) Use FileSink -> Gunzip -> FileSink to inflate the data and reproduce a
copy of the original file
This is the process that produces errors in some files.
Then, once I've done that:
3) Load the .zip file into a buffer
4) Create a Gunzip object and call it, WITHOUT using any sinks or sources
5) Get the data from the Gunzip object and store it in a buffer
6) Write the buffer out
This process never throws any kind of error.
So the first 2 steps use piping, the last 4 do the same thing, without
piping and calling the methods in Gzip. But the first one throws errors.
Even when an error is thrown in Gunzip (while inflating data), the error is
caught and the program continues and the re-constructed file is always a
match to the original file, before it was zipped.
What is the difference here? Why does Gunzip have trouble reading the
header when I use piping at first, while I can read the exact same file and
process it with no errors without piping?
Here is the code from the subroutine. I pass to it the file name and a
number, both of which are only used in creating the filenames for output:
void sinkTest(string inFile, int fileNum) {
using namespace CryptoPP;
cout << "Experimenting file: " << inFile << endl;
//Filenames and such
stringstream xfer;
xfer << fileNum;
string zName = inFile.substr(0, inFile.size() - 4) + "-TestOut.zip";
string z2Name = inFile.substr(0, inFile.size() - 4) + "-TestOut2.zip";
string outName = inFile.substr(0, inFile.size() - 4) + "-TestOut.pdf";
string out2Name = inFile.substr(0, inFile.size() - 4) + "-TestOut2.pdf";
cout << " Zip file: " << zName << endl;
cout << " Out file: " << outName << endl;
//Use streams - first one uses the original file as a source and output is
to a .zip file.
//Second one takes zip as input and deflates it and writes out a test file
for comparions to the original
try {
FileSource((const char*) inFile.c_str(), true, new Gzip( newFileSink((
const char*) zName.c_str()), Gzip::MAX_DEFLATE_LEVEL), true );
cout << " Deflated." << endl;
FileSource((const char*) zName.c_str(), true, new Gunzip( newFileSink((
const char*) outName.c_str()), Gzip::MAX_DEFLATE_LEVEL), true );
cout << " Re-inflated." << endl;
}
catch( CryptoPP::Exception& e ) {
std::cerr << "Error: " << e.what() << std::endl;
}
//Now do it the long way - just DEFLATING. Load the data from the zip file
into a char* array, then feed it to Gunzip
//and let that unpack it. Then get data from Gunzip and save it to a file.
cout << " Loading in zip file..." << endl;
unsigned long zLen;
ifstream inStream(zName.c_str(), ios::in | ios::binary);
inStream.seekg(0, inStream.end);
zLen = inStream.tellg();
inStream.seekg(0, inStream.beg);
char* zData = new char[zLen];
inStream.read(zData, zLen);
inStream.close();
cout << " Unzipping zip file..." << endl;
Gunzip outZip;
outZip.Put((byte*) zData, zLen);
outZip.MessageEnd();
//Current error is here
unsigned long outLen = outZip.MaxRetrievable();
cout << " Output length: " << outLen << endl;
char* outData = new char[outLen];
outZip.Get((byte*) outData, outLen);
ofstream outFile ((char*) out2Name.c_str());
outFile.write(outData, outLen);
outFile.close();
cout << "Returning..." << endl;
return;
}
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.