Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GZipStream or DeflateStream class?

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?

like image 927
Captain Sensible Avatar asked Apr 08 '10 10:04

Captain Sensible


People also ask

What is DeflateStream?

The DeflateStream class uses the same compression algorithm as the gzip data format used by the GZipStream class. The compression functionality in DeflateStream and GZipStream is exposed as a stream.

What is GZipStream C#?

Provides methods and properties used to compress and decompress streams by using the GZip data format specification.

Should I use Brotli?

However, Brotli might perform poorly for non-text files. Therefore, it's better to research before using Brotli for other file types. Finally, since most web apps are developed using JavaScript frameworks like React, Brotli is an excellent option to increase your website's load performance.

What encoding does gzip use?

gzip is based on the DEFLATE algorithm, which is a combination of LZ77 and Huffman coding.


2 Answers

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.

like image 151
Aaronaught Avatar answered Nov 01 '22 07:11

Aaronaught


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

like image 22
agnain Avatar answered Nov 01 '22 07:11

agnain