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

回眸只為那壹抹淺笑 提交于 2019-12-02 05:34:37

问题


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


回答1:


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-




回答2:


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.



来源:https://stackoverflow.com/questions/2987072/sharpziplib-can-you-add-a-file-without-it-copying-the-entire-zip-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!