How to

decompress file using C#

Published: 18. December 2008 | Updated: 26. October 2011
License: Microsoft Public License (MS-PL)
Categories: File system » Files, Streams
Tags: C# File System
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at analyzant.com

Import namespaces

using System.IO;
using System.IO.Compression;

Code

FileStream source = File.OpenRead(@"C:\text.txt.gz");
FileStream destination = File.Create(@"C:\text2.txt");
GZipStream compressionStream = new GZipStream(source, CompressionMode.Decompress);

int readByte = compressionStream.ReadByte();
while (readByte != -1)
{
    destination.WriteByte((byte)readByte);
    readByte = compressionStream.ReadByte();
}

source.Close();
compressionStream.Close();
destination.Close();
Send us feedback about this snippet »



Related Snippets: