简体   繁体   English

用DotNetZip打开Split Zip文件

[英]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)进行提取。

  • There's no need to check if zip entry exsists (isThereItemToExtract). 无需检查zip条目是否存在(isThereItemToExtract)。 Interating the zip entries with foreach should do the job. 将zip条目与foreach进行交互应该可以胜任。
  • To avoid collisions you need to check if file with same name as zipEntry exsists in the unpackDirectory, or use ExtractExistingFileAction.OverwriteSilently flag. 为了避免冲突,您需要检查与zipEntry同名的文件是否存在于unpackDirectory中,或者使用ExtractExistingFileAction.OverwriteSilently标志。

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.

相关问题 使用DotNetZip压缩和解压缩文件 - zip and unzip files using DotNetZip C#压缩库,允许重命名zip包中的文件(不是DotNetZip) - C# Zipping library that allows renaming of files in zip package (not DotNetZip) DotNetZip:拒绝删除和更新受保护的zip中的文件列表 - DotNetZip: Deny removing and updating list of files in protected zip 使用DotNetZip库在内存中嵌套Zip文件和文件夹 - Nesting Zip Files and Folders in Memory using DotNetZip Library 使用DotNetZip从zip中仅提取XML文件 - Extract only XML files from a zip using DotNetZip 使用DotNetZip或SharpZipLib在Classic ASP中创建Zip文件 - Create Zip files in Classic ASP using DotNetZip or SharpZipLib 如何使用DotNetZip为目录中的所有带有密码的文件创建单独的zip文件? - How to create separate zip files for all the files with password within a directory using DotNetZip? HTTP Stream 实现加载远程 ZIP 文件就像本地文件一样 - DotNetZip - HTTP Stream Implementation To Load Remote ZIP Files Just Like Local Files - DotNetZip DotNetZip 使用 ASP.NET 创建的 Zip 文件有时会导致网络错误 - Zip files created by DotNetZip using ASP.NET sometimes causing network error 为什么Windows 7无法从使用DotNetZip创建的受密码保护的zip文件中提取文件? - Why can't Windows 7 extract files from my password protected zip-file created using DotNetZip?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM