Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sharpziplib - can you add a file without it copying the entire zip first?

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

like image 606
schmoopy Avatar asked Dec 27 '25 15:12

schmoopy


1 Answers

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-

like image 199
schmoopy Avatar answered Dec 30 '25 06:12

schmoopy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!