Compressing Streams in Input/Output
In the I/O system inside the .NET Framework, there are two methods for compressing data: GZIP and DEFLATE. Both of these compression methods are industry- standard compression algorithms that are also free for patent protection. Therefore, we are free to use either of these compression methods in our own applications without any intellectual property concerns. These compression methods are exposed by the .NET Framework as two types of streams that support both compression and decompression. These streams are implemented in the GZipStream and DeflateStream classess.
The GZipStream Class
GZipStream is a class that allows the compression of data through to another stream using the GZIP compression method. There are various properties and methods of GZipStream.
GZip properties:
- BaseStream - Gets the underlying stream.
- CanRead - Determines whether the stream supports reading while decompressing a file.
- CanWrite - Determines whether the stream can be written to.
- Canseek - Determines whether the stream supports seeking.
- CanTimeout - Determines whether the stream can timeout.
GZip methods:
- Close - Closes the stream and releases any resources associated with it.
- Flush - Clears any buffers within the stream and forces changes to be written to the underlying system or device.
- Read - Performs a sequential read of a specified number of bytes from the current position and updates the position to the end of the read upon completion of the operation.
- Write - Writes information to the stream as a number of bytes and updates the current position to reflect the new write position.
The DeflateStream Class
DeflateStream is a class that allows the compression of data through to another stream using the DEFLATE compression method.