Jul 29, 2010 at 3:21 PM
Edited Jul 30, 2010 at 6:47 AM
I have old code that uses zlib library from zlib.net and I am trying out this DotNetZip library to use in my new code.
I can deflate the data from the zlib code with DotNetZip, but the zlib code cannot deflate the last block of buffer data from DotNetZip library, so I get invalid data.
I have gone through the code for both libraries and I can see they are mostly the same and I just can't figure out what is causing the problem. This is what happens, the last 4 bytes in the result file are not the same and everything else is same.
I am sending buffer of size 3462929, and in the last loop the value in _codec.Adler32 = 3654184877, which converts to the last 4 bytes = D9 CE
Same buffer goes via the zlib.net code and the value in adler = 2943381421, which converts the last 4 bytes =
AF 70 6F AD.
It's always the first 2 of the 4 last bytes that are different, if you get what I mean.
This is the code block I am using and its same for both libraries, I just switch the using statement and the ZlibStream object between test
FileStream outFileStream = new FileStream(outfile, FileMode.Create);
ZLibStream outZStream = new ZLibStream(outFileStream, CompressionMode.Compress);
FileStream inFileStream = new FileStream(infile, FileMode.Open);
int flen = (int)inFileStream.Length;
byte buffer = new byte[flen + 1];
while ((len = inFileStream.Read(buffer, 0, flen)) > 0)
outZStream.Write(buffer, 0, len);
Edit: I found out that if I compress small 3k xml file, both zip files are same, but if I try 3.4Mb binary data file,
then the mixup in those 2 bytes happens. I am using the DotNetZip lib and Zlib.net lib as is from both websides,
just include them into the project and then run this code above 2 with different Stream objects.