简体   繁体   中英

Opening Split Zip Files With DotNetZip

I am trying to extract files from zip files using the DotNetZip library. I am able to extract files when it is a single .zip file. 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:

-Exception thrown: 'Ionic.Zip.BadReadException' in Ionic.Zip.dll

-Exception thrown: 'Ionic.Zip.ZipException' in Ionic.Zip.dll

Is it possible for DotNetZip to read these type of files, or should I be looking into an alternative approach? I am working on Visual Studios using C#.

Here's a snippet of how I implement my zip file extraction.

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:

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. Every zip entry will be extracted with its full path as specified in the zip archive, relative to the current unpackDirectory.

  • There's no need to check if zip entry exsists (isThereItemToExtract). Interating the zip entries with foreach should do the job.
  • To avoid collisions you need to check if file with same name as zipEntry exsists in the unpackDirectory, or use ExtractExistingFileAction.OverwriteSilently flag.

Is it possible for DotNetZip to read these type of files, or should I be looking into an alternative approach? I am working on Visual Studios using C#.

In my experience, this is the best library to deal with split zip files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM