
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
750
|
Chapter 12: Filesystem I/O
The CompressionType enumeration is defined as follows:
public enum CompressionType
{
Deflate,
GZip
}
Discussion
The CompressFile method accepts a Stream object, data in the form of a byte array,
and a
CompressionType enumeration value indicating which type of compression algo-
rithm to use (Deflate or GZip). This method produces a file containing the com-
pressed data.
The
DeCompressFile method accepts a Stream object and a CompressionType enumera-
tion value indicating which type of decompression algorithm to use (Deflate or
GZip). This method calls the
Decompress method, which reads from a compressed file
and places the data, uncompressed and in the form of bytes, into a generic
List<byte> collection object. This collection object is then converted to a byte[] and
returned with the data to the calling method.
The
TestCompressNewFile method shown in Example 12-17 exercises the CompressFile
and DeCompressFile methods defined in the Solution section of this recipe. It also uses
}
}
else
{
using (reInflate = new GZipStream(strm, CompressionMode.Decompress))
{
return (Decompress(reInflate));
}
}
}
public static byte[] Decompress(Stream reInflate)
{
List<byte> data = new List<byte>( );
int retVal = 0;
// Read all data in and uncompress it.
while (retVal >= 0)
{
retVal ...