Search code examples
c#.netcompression

Decompressing Large Gzip File not working using System.IO.Compression


I have a 3.2GB gzip file that I need decompressed but the output of using my code only produces a 64KB file which is not right.

using (FileStream originalFileStream = fileToDecompress.OpenRead())
{
    string currentFileName = fileToDecompress.FullName;
    string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);

    using (FileStream decompressedFileStream = File.Create(newFileName))
    {
        using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
        {
            decompressionStream.CopyTo(decompressedFileStream);
            Console.WriteLine("Decompressed: {0}", fileToDecompress.Name);
        }
    }
}

I am using .NET 4.5 and the CopyTo method which I understand should work with files larger than 4GB but am having no luck. Any help would be appreciated.


Solution

  • I found a solution but it involved making some code changes to open source unzip project for .NET. Essentially the problem crops up when you have multiple gzip streams and they file is too large. Inside the code an int is being used instead of a long and it is resulting in the behavior I was experiencing. Once the code was modified it worked as expected.