Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata