从 GzipStream 解压缩时,出现 IO 异常“GZip 页脚中的流大小与实际流大小不匹配”。这个错误在多个文件上 100% 发生,所以我不相信这是一个“真正的”损坏文件问题。
压缩代码如下:
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);
}
}
}
抛出异常的解压代码如下:
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);
}
}
}