The GZipStream class is a part of the System.IO.Compression namespace. This class is used for the compression of data. Before the .NET 2.0 Framework, the only choice we had for compression were third party tools.
–
Common Methods (Full List)
- BeginRead – Begins an asynchronous read operation.
- BeginWrite – Begins an asynchronous write operation.
- Close – Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
- EndRead – Waits for the pending asynchronous read to complete.
- EndWrite – Handles the end of an asynchronous write operation.
- Read – Reads a number of decompressed bytes into the specified byte array.
- Write – Writes compressed bytes to the underlying stream from the specified byte array.
–
Below is a simple C# console application that takes an input file, compresses it and creates a compressed zip file.
View the C# code sample [HERE]
–
The command-line illustration below shows the application at work.
- If no argument is provided, the usage syntax is echoed to the screen
- If the argument provided cannot be located, error is echoed to the screen
- If correct argument is provided, the file is compressed and a new file is created
The result (compressed) file created.
View the compressed file in a Zip application.
–
The GZipStream class is not as feature-rich as the third-party tools, but it is a convenient way to compress data.
–
Related Content
–
Happy programming…
[...] File Compression Using the .NET GZipStream Class (Rhonda Tipton) [...]
By: Dew Drop – June 8, 2008 | Alvin Ashcraft's Morning Dew on June 8, 2008
at 6:20 am
[...] File Compression Using the .NET GZipStream Class – Rhonda Tipton ‘ The GZipStream class is not as feature-rich as the third-party tools, but it is a convenient way to compress data ‘ [...]
By: Arjan`s World » LINKBLOG for June 9, 2008 on June 9, 2008
at 8:24 am