0

I am able to compress up to 1 GB of the folder but I have to compress more than 10 GB.

 string filePath  = C:\Work; // path of the source file 
 private void compressFile(string filePath)
 {
     using (ZipFile zip = new ZipFile())
     {                    
        zip.AddDirectory(Path.Combine(filePath, "Demo"));
        if (File.Exists(Path.Combine(filePath, "Demo.zip")))
        {
           File.Delete(Path.Combine(filePath, "Demo.zip"));
           zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;                
           zip.Save(Path.Combine(filePath, "Demo.zip"));                        
         }   

         zip.Save(Path.Combine(filePath, "Demo.zip"));               
       }      
    }
stuartd
  • 70,509
  • 14
  • 132
  • 163
Dutt93
  • 118
  • 10
  • 1
    I got This Exception... Unable to compressIonic.Zip.ZipException: Compressed or Uncompressed size, or offset exceeds the maximum value. Consider setting the UseZip64WhenSaving property on the ZipFile instance. at Ionic.Zip.ZipEntry.SetZip64Flags() at Ionic.Zip.ZipEntry.PostProcessOutput(Stream s) at Ionic.Zip.ZipEntry._WriteEntryData(Stream s) at Ionic.Zip.ZipEntry.Write(Stream s) at Ionic.Zip.ZipFile.Save() – Dutt93 Jun 21 '17 at 10:00
  • Zip files are I believe limited to a maximum of 4GB in size – stuartd Jun 21 '17 at 10:01
  • @stuartd zip64 extends that to 16 billion gigabytes; the first thing to try, then, is *exactly what the exception message says*; however, I'd still be very worried about the amount of data to buffer in memory – Marc Gravell Jun 21 '17 at 10:04
  • @MarcGravell yeah, I should have mentioned zip64. – stuartd Jun 21 '17 at 10:04
  • @stuartd I have 15 GB of a folder which is having only text files, after zipping it will become nearly 2GB. – Dutt93 Jun 21 '17 at 10:05
  • It may _end up_ at that size, but the error message is clearly telling you that something along the way is exceeding the maximum. – stuartd Jun 21 '17 at 10:08
  • 1
    [This question](https://stackoverflow.com/questions/14901652/net-ionic-zip-module-killing-drive-space) is related – stuartd Jun 21 '17 at 10:08

1 Answers1

6

I'm assuming the issue here is out-of-memory due to the fact that everything is in memory until the zip.Save call.

Suggestion: don't use DotNetZIP. If you use System.IO.Compression.ZipArchive instead, you start by giving it an output stream (in the constructor). Make that a FileStream and you should be set, without it needing to buffer everything in memory first.

You would need to use ZipArchiveMode.Create

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900