gpt4 book ai didi

c# - GZipStream 有效但扩展名丢失

转载 作者:太空狗 更新时间:2023-10-29 18:08:42 27 4
gpt4 key购买 nike

我正在使用以下代码来压缩文件并且它工作正常但是当我使用 WinRar 解压缩时我得到没有扩展名的原始文件名,任何线索为什么如果文件名是 myReport.xls 当我解压缩我只得到 myReport ?

using (var fs = new FileStream(fileName, FileMode.Open))
{
byte[] input = new byte[fs.Length];
fs.Read(input, 0, input.Length);
fs.Close();

using (var fsOutput = new FileStream(zipName, FileMode.Create, FileAccess.Write))
using(var zip = new GZipStream(fsOutput, CompressionMode.Compress))
{
zip.Write(input, 0, input.Length);
zip.Close();
fsOutput.Close();
}
}

最佳答案

GZip 只压缩一个文件——不知道名字。因此,如果您压缩文件 myReport.xls,您应该将其命名为 myReport.xls.gz。解压缩时,最后一个文件扩展名将被删除,因此您最终得到原始文件名。

这就是它在 Unix/Linux 中使用多年的方式...

关于c# - GZipStream 有效但扩展名丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7766636/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com