views:

423

answers:

2

The MSDN documentation tells me the following:

The GZipStream class uses the gzip data format, which includes a cyclic redundancy check value for detecting data corruption. The gzip data format uses the same compression algorithm as the DeflateStream class.

It seems GZipStream adds some extra data to the output (relative to DeflateStream). I'm wondering, in what type of a scenario would it be essential to use GZipStream and not DeflateStream?

+1  A: 

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.

n535
+1  A: 

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.

Aaronaught