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);
}
}
}