GZipStream or DeflateStream class?

Solution 1:

Deflate is just the compression algorithm. GZip is actually a format.

If you use the GZipStream to compress a file (and save it with the extension .gz), the result can actually be opened by archivers such as WinZip or the gzip tool. If you compress with a DeflateStream, those tools won't recognize the file.

If the compressed file is designed to be opened by these tools, then it is essential to use GZipStream instead of DeflateStream.

I would also consider it essential if you're transferring a large amount of data over an unreliable medium (i.e. an internet connection) and not using an error-correcting protocol such as TCP/IP. For example, you might be transmitting over a serial port, raw socket, or UDP. In this case, you would definitely want the CRC information that is embedded in the GZip format in order to ensure that the data is correct.

Solution 2:

GZipStream is the same as DeflateStream but it adds some CRC to ensure the data has no error.

Solution 3:

Well, i was completely wrong in my first answer. I have looked up in Mono source code and found that GZipStream class actually redirects its read/write(and almost any other) calls to an appropriate calls of methods of an internal DeflateStream object:

public override int Read (byte[] dest, int dest_offset, int count)
{
    return deflateStream.Read(dest, dest_offset, count);
}

public override void Write (byte[] src, int src_offset, int count)
{
    deflateStream.Write (src, src_offset, count);
}

The only difference, is that it always creates a DeflateStream object with a gzip flag set to true. This is certainly not an answer to you question, but maybe it'll help a bit.