I
have a question.
I'm
trying to compress and uncompress messages using the same Hoffman table.
the compress looks fine but the
uncompress fails.
I'm
using version 5.2.1.
please advise,
Ofer
#include "stdafx.h"
#include <fstream>
#include <crypto/gzip.h>
int main(int
argc, char* argv[])
{
unsigned char chunk[65536];
unsigned char compressedBuffer[128000];
unsigned char decompressedBuffer[65536];
size_t decompressedSize;
CryptoPP::Gzip compressor;
CryptoPP::Gunzip decompressor;
int pos = 0;
FILE* in = fopen("c:\\temp\\in",
"rb");
while(!feof(in))
{
// Comp
size_t compressedSize;
size_t readBytes = fread(chunk, 1,
65536, in);
printf("Compressing %d - %d\n", pos, pos+readBytes);
pos += readBytes;
compressedSize
= readBytes;
compressor.PutMessageEnd(chunk, (unsigned int)readBytes);
compressedSize
= compressor.MaxRetrievable();
compressor.Get(compressedBuffer,(unsigned int)compressedSize);
compressor.GetNextMessage();
printf("\t compressed size: %d\n", compressedSize);
// Decomp
decompressor.PutMessageEnd(compressedBuffer, (unsigned int)compressedSize);
decompressedSize
= decompressor.MaxRetrievable();
decompressor.Get(decompressedBuffer,(unsigned int)decompressedSize);
decompressor.GetNextMessage();
printf("\t decompressed size: %d\n", decompressedSize);
assert(decompressedSize
== readBytes);
assert(memcmp(chunk,
decompressedBuffer, readBytes)
== 0);
}
fclose(in);
return 0;
}
Output:
Compressing 0 - 65536
compressed
size: 3352
decompressed
size: 65536
Compressing 65536 - 131072
compressed
size: 3334
decompressed
size: 0
Assertion failed: decompressedSize == readBytes