DeflateStream Class
Part of my 2008 study notes for exam 70-536 (.NET Framework 2.0).
Overview
- Used to compress and decompress data.
- Slightly smaller result than GZipStream because of lack of header information.
- Use for internal use in your own application.
- Works like a BufferedStream as it sits on top of another stream.
- Limited to files up to 4GB (uncompressed).
Good practice
- Remember to call Close on a stream.
Compress File
FileStream fileIn = File.OpenRead(@"C:\Public\Test.txt");
FileStream fileOut = File.OpenWrite(@"C:\Public\TestComp.txt");
DeflateStream compress = new DeflateStream(fileOut, CompressionMode.Compress);
byte[] buffer = new byte[fileIn.Length];
fileIn.Read(buffer, 0, buffer.Length);
compress.Write(buffer, 0, buffer.Length);
compress.Close();
fileIn.Close();
fileOut.Close();
Decompress File
FileStream compressedFile = File.OpenRead(@"C:\Public\TestComp.txt");
DeflateStream decompress = new DeflateStream(compressedFile, CompressionMode.Decompress);
StreamReader read = new StreamReader(decompress);
Console.WriteLine(read.ReadToEnd());
read.Close();
decompress.Close();
compressedFile.Close();
You May Also Like
ArrayList Class
Resizeable, unordered, index-based collection. Suffers from boxing/unboxing when working with value types. Implements IEnumerator, allowing foreach…
BinaryReader Class and BinaryWriter Class
Used to read and write binary data from streams. Call the correct Read methods when using a BinaryReader.
BitArray Class
Contains an array of true/false values. Resizable through the Length property. Supports bitwise operations.



