I need cross-platform compression/decompression between Windows and Ubuntu. As I understand, starting .NET 4.5, class DeflateStream uses zlib as the compression libraries. I have written two small test programs to compress data, one in C# running on Windows and the other in 'C' running on Ubuntu. The .NET platform is 4.5.2.
C# code is using CompressionLevel.Optimal
C code is using Z_BEST_COMPRESSION
Here are the results:
Input bytes: {9, 12, 13}
C# output: {227, 228, 225, 5, 0};
C output: {120, 218, 227, 228, 225, 5, 0, 0, 67, 0, 35}
As you can see, the length of compressed data in C# is 5 bytes where as in C is 11 bytes. It seems 'C' zlib is adding 2 extra bytes in header and 4 extra bytes in footer.
If needed, I can share the code. However, it is taken from standard examples that you see on the net and there is nothing special about the code.
Am I missing something? Is there a way to fix it? If the header and the footer always stay the same, perhaps I can always add the additional bytes. Regards.