0
votes

I'm getting an IO exception "The stream size in GZip footer does not match the real stream size" when decompressing from GzipStream. This error is occurring 100% of the time on multiple files so I don't believe that this is a "real" corrupt file issue.

The compression code is as follows:

 using (var fileStream = fileInfo.OpenRead())
            {
                using (var outFile = File.Create(Path.Combine(backupLocation, backupFileName.ToString())))
                {
                    using (var gzCompressionStream = new GZipStream(outFile, CompressionMode.Compress))
                    {
                        fileStream.CopyTo(gzCompressionStream);
                    }
                }
            }

The decompression code which is throwing the exception is as follows:

using (var fileStream = fileInfo.OpenRead())
            {
                // remove the extension
                var fileName = fileInfo.Name;
                var originalName = fileName.Remove(fileName.Length - fileInfo.Extension.Length);

                using (var outFile = File.Create(Path.Combine(transferLocation, originalName)))
                {
                    using (var gzDecompressionStream = new GZipStream(fileStream,CompressionMode.Decompress))
                    {
                        gzDecompressionStream.CopyTo(outFile);
                    }
                }
            }
1
Code looks reasonable. Have you verified that file names are expected (i.e. check for one file with hard-coded name compress ->decompress)?Alexei Levenkov
Sorry not quite sure I follow you, how would the filename affect decompression ?Johnv2020
I.e. Compression: "Source.txt" -> "compressed.compr", decompression: "random.file" (instead of "compressed.compr") -> "Source.txt" (fails as "random.file" is not compressed at all).Alexei Levenkov
Could you post a short, but complete sample that we could run that shows your problem?svick

1 Answers

1
votes

All, thanks for your help - looks like I've found the problem. I'm only getting an error when the compressed file size is greater than 4GB, below this everything works fine, - this shouldn't be a problem as MSDN states that GZipStream works for file sizes up to 8GB with .Net 4 (which I'm using) and the maximum file size will always be below 6GB (application limit). Previous versions of GZipStream only supported up to 4GB however - it looks as if the MSDN documentation is incorrect in this case.