views:

221

answers:

2

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 :-)

A: 

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.

allonym
Yea im trying to add to an existing zip file :-(
schmoopy
+2  A: 

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-

schmoopy
Would be good to quote the answer here so it's easier for others to read.
Davy8
Good point Davy, i added the quote, thank you.
schmoopy