Question

Im trying to add a file to an existing .zip file using sharpziplib - problem is, the zip file is 1GB in size. When i try to add 1 small file (400k) sharpziplib creates a copy/temp of the orig zip file before adding the new file - this poses a problem when the amount of free disk space is less than 2x the zip file you are trying to update.

for example: 1GB zip myfile.zip 1GB zip myfile.zip.tmp.293

ZipFile zf = new ZipFile(path);
zf.BeginUpdate();
zf.Add(file);   // Adding a 400k file here causes a 1GB temp file to be created
zf.EndUpdate();
zf.Close();

Is there a more efficient way to do this?

Thanks :-)

Was it helpful?

Solution

Found the answer:

http://community.sharpdevelop.net/forums/p/5934/17056.aspx#17056

Hi,

If you are creating a new Zip archive is might be easier to use the ZipOutputStream class instead.

If you are updating you can get the ZipFile class to write directly to the existing archive on disk if you choose. IArchiveStorage (The library supplies a DiskArchiveStorage) is the key interface passed when BeginUpdate is called. It has a UpdateMode property which can be set to Safe or Direct.

The implications are obvious hopefully. Failure during an update may corrupt the archive losing the data.

hth, -jr-

OTHER TIPS

If you're creating the zip file from scratch, use ZipOutputStream instead of ZipFile. You can find an example of this in the SharpZipLib sources. I'm not sure if ZipOutputStream supports adding to an existing zip file, so if that's what you're doing I'm afraid I don't have a useful answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top