我正在尝试将文件解压缩到内存流中,但仍然会收到“无法访问已关闭的文件”。例外。我正在使用DotNetZip并具有以下堆栈跟踪:
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.get_Position()
at Ionic.Zip.ZipEntry.SetFdpLoh()
at Ionic.Zip.ZipEntry.get_FileDataPosition()
at Ionic.Zip.ZipEntry.InternalOpenReader(String password)
at Ionic.Zip.ZipEntry.OpenReader()
以下是抛出错误的代码段:
foreach (Ionic.Zip.ZipEntry zipEntry in zip.Entries)
{
if (zipEntry.FileName == "PS/DEANS.svg")
{
//wait!
}
Logger.WriteToLog(zipEntry.FileName);
string _extension = FileUtil.GetFileExtension(zipEntry.FileName);
if (fileExtensionsLowerCase.Contains(_extension))
{
string _fileName = FileUtil.GetFileName(zipEntry.FileName, "/", false).ToUpper();
string _folderName = FileUtil.GetParentFolder(zipEntry.FileName, "/").ToUpper();
// Extract the file to a memory stream
using (var entry = zipEntry.OpenReader())
{
entry.LeaveOpen = false;
byte[] buffer = new byte[entry.Length];
entry.Read(buffer, 0, Convert.ToInt32(entry.Length));
byte[] digest = Common.GetSha256Digest(buffer);
svgCollection.Add(new SVG { fileName = _fileName, folderName = _folderName, fileHashDigest = digest });
digest = null;
}
_fileName = _folderName = _extension = null;
}
}
有没有人对可能引发错误的内容有任何想法?我相当肯定我没有尝试打开同一个文件两次,因为我在zip.Entries集合上使用foreach。我不确定这是否是DotNetZip问题还是我的代码?
仅当我尝试提取特定文件“PS / DEANS.svg”时才会出现此问题。