I need to implement a special ZLib implementation which should run under .Net and Mono. The data /string messages are received via a socket and thus the checksum is missing. This is about raw string data, not about files.
unsigned char zlib_header[]={
// custom additional Zlib Id
'Z', // Our own ID
// The normal GZIP header
0x1f,
0x8b, // GZIP ID
0x08, // Deflated
0x00, // Flags
0, 0, 0, 0, // Timestamp,
0x00, // Extra flags
0x00, // OS identifier
// afterwards compressed data without a checksum
};
I have tried to decompress the data with GZipStream and DeflateStream, but I think that GZStream fails because of the missing checksum. I have also tried various offsets, but had no luck. The checksum is not used because the data is received via a socket anyway - thus the ZLib checksum would be additional overhead. Have I missed something or could you explain me how to add the checksum and call the right library then or should I look at a 3rd party library which supports Mono and .Net? Edit: Performance is very critical as this done at least once a second. Would you recommend me at the end to use the C-Lib via Interop? I always receive Invalid Data Exception at the moment and I assume that it is related to the wrong checksum. This is the actual code which I tried to use without success:
const int HeaderSize = 1;
System.IO.MemoryStream ms = new System.IO.MemoryStream(compressedBuffer, HeaderSize, compressedBuffer.Length-HeaderSize);//remove the additional Z from the header
GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress,true);
byte[] deCompressedBytes = new byte[actualBufferLength* 10];
int resultSize=zipStream.Read(deCompressedBytes, 0, actualBufferLength);//get rid of the header
UTF8Encoding enc = new UTF8Encoding();
string result = enc.GetString(deCompressedBytes, 0, resultSize);