zip and unzip files using DotNetZip

瘦欲@ 提交于 2020-01-07 04:17:06

问题


I am using DotNetZip. Using it to zip mp3 files.

ZipFile zip = new ZipFile();
zip.Password = "123";
zip.AddFile("R:\\abc\\a\\a 2 z.mp3");
zip.Save("R:\\abc\\a\\aaa.zip");

After extraction of aaa.zip, I get a corrupted mp3 file. Having 3.31MB data when original had 3.62MB. How to resolve this problem? Any help is appreciated.


回答1:


The documentation states here:

Be aware that the ZipFile class implements the IDisposable interface. In order for ZipFile to produce a valid zip file, you use use it within a using clause (Using in VB), or call the Dispose() method explicitly. See the examples for how to employ a using clause.

So try to wrap your code in a using block:

using (ZipFile zip = new ZipFile())
{
   zip.Password = "123";
   zip.AddFile("R:\\abc\\a\\a 2 z.mp3");
   zip.Save("R:\\abc\\a\\aaa.zip");
}

Also refer to the various example on Save documentation page.




回答2:


The problem is really unknown. The problem happens for only that specified file. I've tried with other files and found no problems. Thank you guys.



来源:https://stackoverflow.com/questions/13788140/zip-and-unzip-files-using-dotnetzip

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