Overview
- Used to compress and decompress data.
- Slightly smaller result than GZipStream because it lacks header information.
- Intended 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.
Examples
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

Exam 70-536 Study Notes
My study notes for Microsoft exam 70-536: .NET types, collections, generics, I/O, serialization and more, with C# examples.

Starting Exam 70-536 Study
After a burnout, I'm putting my own project on hold to study for Microsoft exam 70-536.

Design Patterns - Proxy Pattern
The Proxy Pattern, and the last article in the design patterns series, now that I've finished reading Head First Design Patterns.




