from
http://blogs.msdn.com/b/bclteam/archive/2005/06/15/429542.aspx[
^]
private static void Compress(Stream source, Stream destination)
{
using(GZipStream output = new GZipStream(destination, CompressionMode.Compress)) {
Pump(source, output);
}
}
private static void Decompress(Stream source, Stream destination)
{
using(GZipStream input = new GZipStream(source, CompressionMode.Decompress)) {
Pump(input, destination);
}
}
private static void Pump(Stream input, Stream output)
{
byte[] bytes = new byte[4096];
int n;
while((n = input.Read(bytes, 0, bytes.Length)) != 0) {
output.Write(bytes, 0, n);
}
}
...
String inputFileName = @"fully qualified path to input file";
String outputFileName = @"fully qualified path to output file";
Stream src = null;
Stream dest = null;
dest = File.Create(outputFileName);
using(src = File.OpenRead(inputFleName)) {
using(dest)
{
Decompress(src, dest);
}
}