Reputation: 7240
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.
Upvotes: 0
Views: 795
Reputation: 112512
I highly recommend that you use DotNetZip's interface to zlib instead of NET 4.5's. NET 4.5 has bugs in that interface that Microsoft has declared that they won't fix (!).
Update:
This answer from 2016 is out of date. DotNetZip has been deprecated, where it is recommended to transition to System.IO.Compression.
Upvotes: 3
Reputation: 7240
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.
Upvotes: 0