2

I have this code, where zipfilename is an existing Zip file, sourceFile is a file I want to compress, and filename is the archive entry name.

using (ZipArchive archive = ZipFile.Open(zipfilename, ZipArchiveMode.Update))
{
    await Task.Run(() => archive.CreateEntryFromFile(sourceFile, filename, CompressionLevel.Fastest));
}

This works great for small files, no larger than say 50KB. For these, the file is compressed into the archive no problem. I can add as many small files as I want this way.

But for very large files 1.8GB in size, memory consumption shoots up to several GB, and the file never actually compresses into the archive.

How can I better handle compressing large files into an existing destination archive? Note that I need to use an existing destination zip / archive file, and it must be .zip.

CarenRose
  • 1,266
  • 1
  • 12
  • 24
Dshiz
  • 3,099
  • 3
  • 26
  • 53
  • What zip library do you use ? – Graffito Jul 08 '15 at 10:18
  • I'm using System.IO.Compression. I'm aware of some Nuget packages, but read that there are stability issues for large files.. – Dshiz Jul 08 '15 at 10:22
  • 1
    I am not sure, but system.Io.compression may not support zip64 format that breaks the limitation of the maximum addressible size for a 32-bit pointer (i.e. uint 4GB, int 2GB). But, it doesn't explain why a 1.8 GB file won't compress. – Graffito Jul 08 '15 at 12:11
  • SharpZipLib available on Nuget certainly handles large files better than System.IO.Compression. – Dshiz Jul 09 '15 at 05:14
  • Okay, now with SharpZipLib I'm going in circles. I can better handle compressing a large file initially, but I can't seem to make it add files to an existing archive that might have started with a small file. What happens is the small file is overwritten by the large file in the archive. Should I post a new question? or should I update this question with example code.. – Dshiz Jul 09 '15 at 05:22

1 Answers1

3

I know this is a tad too late. But, instead of using ZipArchiveMode.Update, why don't you unzip the archive file into a temporary folder, delete the zip and zip all your files including the one's in your temp folder together using ZipArchiveMode.Create (if you are working with existing zips). This will be a faster process and can process larger destination zips.

CarenRose
  • 1,266
  • 1
  • 12
  • 24
Monil
  • 31
  • 1
  • 5