sharpziplib-您可以添加文件而不先复制整个zip吗? [英] sharpziplib - can you add a file without it copying the entire zip first?

查看:100
本文介绍了sharpziplib-您可以添加文件而不先复制整个zip吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Sharpziplib将文件添加到现有的.zip文件中-问题是,该zip文件的大小为1GB.当我尝试添加1个小文件(400k)时,Sharpziplib在添加新文件之前创建了orig zip文件的副本/临时文件-当可用磁盘空间量小于您要尝试的zip文件的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.

例如: 1GB zip myfile.zip 1GB zip myfile.zip.tmp.293

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();

有没有更有效的方法?

谢谢:-)

推荐答案

找到了答案:

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

如果要创建新的Zip存档 可能更容易使用 改为使用ZipOutputStream类.

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

如果您要更新,则可以获取 ZipFile类直接写入 磁盘上的现有存档(如果您) 选择. IArchiveStorage(库 提供DiskArchiveStorage)是 BeginUpdate传递时通过的关键接口 叫做.它具有一个UpdateMode 可以设置为安全"或 直接的.

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-

这篇关于sharpziplib-您可以添加文件而不先复制整个zip吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆