【发布时间】:2022-11-09 23:43:45
【问题描述】:
我使用 SharpZipLib 解压缩文件。 为此,我使用以下代码:
using (var fsInput = File.OpenRead(zipFile))
using (var zf = new ZipFile(fsInput)) {
zf.Password = password;
foreach (ZipEntry zipEntry in zf) {
if (!zipEntry.IsFile) {
// Ignore directories
continue;
}
var entryFileName = zipEntry.Name;
// Manipulate the output filename here as desired.
var fullZipToPath = Path.Combine(Settings.Default.ConsTemp, entryFileName);
// 4K is optimum
var buffer = new byte[4096];
// Unzip file in buffered chunks. This is just as fast as unpacking
// to a buffer the full size of the file, but does not waste memory.
// The "using" will close the stream even if an exception occurs.
using (var zipStream = zf.GetInputStream(zipEntry))
using (Stream fsOutput = File.Create(fullZipToPath)) {
StreamUtils.Copy(zipStream, fsOutput, buffer);
}
}
}
我总是例外Invalid password。当我在 Windows 中尝试使用相同的解压缩密码时,它可以正常工作。
有谁知道 SharpZipLib 没有正确使用密码可能是什么问题?
【问题讨论】:
标签: c# sharpziplib