Decompressing a GZip File

Oct 6, 2009 at 7:43 PM

Do you have any examples for unzipping a GZip file in C#?

Coordinator
Oct 6, 2009 at 7:52 PM

In the doc for GZipStream

private void GunZipFile(string filename)
{
    if (!filename.EndsWith(".gz))
        throw new ArgumentException("filename");
    var DecompressedFile = filename.Substring(0,filename.Length-3);
    byte[] working = new byte[WORKING_BUFFER_SIZE];
    int n= 1;
    using (System.IO.Stream input = System.IO.File.OpenRead(filename))
    {
        using (Stream decompressor= new Ionic.Zlib.GZipStream(input, CompressionMode.Decompress, true))
        {
            using (var output = System.IO.File.Create(DecompressedFile))
            {
                while (n !=0)
                {
                    n= decompressor.Read(working, 0, working.Length);
                    if (n > 0) 
                    {
                        output.Write(working, 0, n);
                    }
                }
            }
        }
    }
}

Oct 6, 2009 at 7:58 PM

Thank you,  I must have missed that example.