This topic demonstrates how to decompress a GZip compressed byte array using the static Decompress method of the XceedCompressedStream class.
For the purposes of this example we used the Decompress method of XceedCompressedStream class; however, we could have also used the Decompress method of the GZipCompressedStream or the ZLibCompressedStream classes.
Basic steps
To decompress a compressed byte array, the following steps must be taken:
- Retrieve a byte array containing the compressed data. For the purposes of this example, our compressed data is the data compressed using the Compress example.
- Decompress the data. The resulting compressed data will be returned as a byte array.
Example
The following example demonstrates how to compress an array of bytes using the static Decompress method of the GZipCompressedStream class.
Things you should consider
The main questions you should ask yourself when decompressing data read from a stream are:
- Do you want to decompress byte arrays compressed using the Xceed or GZip formatted compressed streams? Use the static Decompress method of the GZipCompressedStream or ZLibCompressedStream classes instead of the XceedCompressedStream's.
- Do you want to decompress a byte array that was compressed without a compression format (raw data)? Use the Decompress method of the QuickCompression class.
- Do you want to decompress data as it is read from a stream? Use the Read method of the desired compression format class.
- Do you need to convert the resulting decompressed byte array to a string? Use the GetString method of the .NET Framework's System.Text.Encoding class.