[英]Opening Split Zip Files With DotNetZip
I am trying to extract files from zip files using the DotNetZip library. 我试图使用DotNetZip库从zip文件中提取文件。 I am able to extract files when it is a single .zip file.
我可以在单个.zip文件中提取文件。 However, when I try to extract files from a multi volume zip file like Something.zip.0 or Something.zip.1, I get the following two exceptions:
但是,当我尝试从Something.zip.0或Something.zip.1等多卷zip文件中提取文件时,我得到以下两个例外:
-Exception thrown: 'Ionic.Zip.BadReadException' in Ionic.Zip.dll -Exception抛出:Ionic.Zip.dll中的'Ionic.Zip.BadReadException'
-Exception thrown: 'Ionic.Zip.ZipException' in Ionic.Zip.dll -Exception抛出:Ionic.Zip.dll中的'Ionic.Zip.ZipException'
Is it possible for DotNetZip to read these type of files, or should I be looking into an alternative approach? DotNetZip可以读取这些类型的文件,还是应该研究另一种方法? I am working on Visual Studios using C#.
我正在使用C#从事Visual Studio。
Here's a snippet of how I implement my zip file extraction. 这是我如何实现我的zip文件提取的片段。
using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(_pathToZip))
{
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;
foreach(Ionic.Zip.ZipEntry ze in zip)
{
string fileName = ze.FileName;
bool isThereItemToExtract = isThereMatch(fileName.ToLower(), _folderList, _fileList);
if (isThereItemToExtract)
{
string pathOfFileToExtract = (_destinationPath + "\\" + ze.FileName).Replace('/', '\\');
string pathInNewZipFile = goUpOneDirectoryRelative(ze.FileName);
ze.Extract(_destinationPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
_newZip.AddItem(pathOfFileToExtract, pathInNewZipFile);
}
}
_newZip.Save();
}
Please refer the DotNetZipLibrary code examples: 请参考DotNetZipLibrary代码示例:
using Ionic.Zip;
private void MyExtract(string zipToUnpack, string unpackDirectory)
{
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
foreach (ZipEntry e in zip1)
{
e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
}
This method should be able to extract either split and not split zip files. 此方法应该能够提取拆分和不拆分zip文件。 Every zip entry will be extracted with its full path as specified in the zip archive, relative to the current unpackDirectory.
每个zip条目将使用zip存档中指定的完整路径(相对于当前的unpackDirectory)进行提取。
Is it possible for DotNetZip to read these type of files, or should I be looking into an alternative approach?
DotNetZip可以读取这些类型的文件,还是应该研究另一种方法? I am working on Visual Studios using C#.
我正在使用C#从事Visual Studio。
In my experience, this is the best library to deal with split zip files. 根据我的经验,这是处理拆分zip文件的最佳库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.