压缩问题,在DotNetZip大的存档文件 [英] Compression issue with large archive of files in DotNetZip

查看:591
本文介绍了压缩问题,在DotNetZip大的存档文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候....



我在C#3.5编写的备份程序,采用最新的兴田DotNetZip。该方案的基础是获得一个服务器上的位置和跨区zip文件的最大尺寸而归。从那里它应该从给定的位置遍历所有的文件夹/文件,并把它们添加到档案,保持的确切结构。它也应该压缩一切下降到一个合理的金额。的文件夹/文件给定的未压缩的集合可以很容易地10-25gb,与创建的跨区文件被限制在1GB左右各



我所拥有的一切工作(使用DotNetZip) 。我唯一的挑战是有一点没有compession实际发生的情况。我选择使用的代码简单的AddDirectory的方法,只是一般它似乎多么适合我的项目。看完围绕我的第二个猜测该决定后。




  1. 由于下面的代码并存档中的大量文件,应我压缩每个文件,因为它被添加到拉链?还是应该Adddirectory方法提供大约相同的压缩?


  2. 我曾尝试通过Ionic.Zlib.CompressionLevel提供压缩的各个层面,并没有似乎帮助。我应该考虑使用外部的压缩算法,并流进我的DotNetZip文件?






 使用(的ZipFile邮编=新的ZipFile())
{
zip.AddDirectory(root.FullName);

如果(zipPassword.Length大于0)
zip.Password = zipPassword;

浮动大小= zipGbSize * 1024 * 1024 * 1024;

zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddProgress + =新的EventHandler< AddProgressEventArgs>(Zip_AddProgress);
zip.ZipError + =新的EventHandler< ZipErrorEventArgs>(Zip_ZipError);
zip.Comment = + System.DateTime.Now.ToString(G)这个zip是在创造;
zip.MaxOutputSegmentSize =(int)的大小; //在演出
zip.Name = archiveDir.FullName + @\Task_+ taskId.ToString()+.ZIP
zip.Save();
}

感谢您的帮助!


解决方案

1.Given下面的代码并存档中的大量文件,我应该压缩的每个文件,因为它被添加到压缩?




DotNetZip的工作方式是,因为它被添加到档案来压缩每个文件。您的应用程序并不需要做的压缩。 DotNetZip做这个给你。




还是应该Adddirectory方法提供大约相同的压缩?




条目添加到通过AddDirectory()方法,通过相同的代码路径的zip压缩文件写入时,因为通过AddFile添加的条目()的zip文件。文件数据进行压缩,然后有选择地进行加密,然后再写入到zip文件。






未经请求提示:你并不需要做的:

  zip.AddProgress + =新的EventHandler< AddProgressEventArgs>(Zip_AddProgress); 



你可以这样做:

  zip.AddProgress + = Zip_AddProgress; 






你是如何确定没有压缩发生?



如果您想了解关于每个条目的压缩,你可以注册一个SaveProgress事件处理程序。该SaveProgress事件存档,包括何时储蓄开始,DotNetZip开始一个条目的撰写过程中编写一个条目中的数据,在不同的时间间隔,完成每个条目写入数据后时的写作过程中在不同的时间解雇,写完所有数据之后。这些阶段和的ZipProgressEventType枚举。当事件类型是Saving_AfterWriteEntry,可以计算出该特定条目的压缩比。



要验证压缩没有发生,我建议您注册这样一个SaveProgress事件,并期待在该压缩比。



另外,如上所述,某些文件类型不能被压缩。 JPG,MPG,MP3,ZIP文件和其他人都不是很压缩。






最后,做一个备份可能会有很多更容易做,如果你只是使用DotNetZip命令行工具。如果你想要做的是备份一个特定的目录,你可以使用命令行工具(zipit.exe),并避免编写的程序。随着zipit.exe工具,如果你使用-v选项,工具打印进度报告,并会显示每个条目的压缩,通过我上面描述的机制。即使你喜欢编写自己的程序,你可以考虑使用zipit.exe当您使用DotNetZip验证压缩是,或不是,发生的历史。


Greetings....

I am writing a backup program in c# 3.5, using hte latest DotNetZip. The basics of the program is to be given a location on a server and the max size of a spanned zip file and go. From there it should traverse all the folder/files from the given location and add them to the archive, keeping the exact structure. It should also compress everything down to a reasonable amount. A given uncompressed collection of folders/files could easily be 10-25gb, with the created spanned files being limited to about 1gb each.

I have everything working (using DotNetZip). My only challenge is there is little to no compession actually happening. I chose to use the "AddDirectory" method for simplicity of code and just generally how well it seemed to fit my project. After reading around I am second guessing that decision.

  1. Given the below code and the large amount of files in an archive, should I compress each file as it is added to the zip? or should the Adddirectory method provide about the same compression?

  2. I have tried every level of compression offered by Ionic.Zlib.CompressionLevel and none seem to help. Should I think about using an outside compression algorithm and stream it into my DotNetZip file?

using (ZipFile zip = new ZipFile())  
{  
  zip.AddDirectory(root.FullName);  

  if (zipPassword.Length > 0)  
    zip.Password = zipPassword;  

  float size = zipGbSize * 1024 * 1024 * 1024;  

  zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;  
  zip.AddProgress += new EventHandler<AddProgressEventArgs>(Zip_AddProgress);  
  zip.ZipError += new EventHandler<ZipErrorEventArgs>(Zip_ZipError);  
  zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");  
  zip.MaxOutputSegmentSize = (int)size;   //in gig  
  zip.Name = archiveDir.FullName + @"\Task_" + taskId.ToString() + ".zip";  
  zip.Save();  
}  

Thank you for any help!

解决方案

1.Given the below code and the large amount of files in an archive, should I compress each file as it is added to the zip?

The way DotNetZip works is to compress each file as it is added to the archive. Your app does not need to do compression. DotNetZip does this for you.

or should the Adddirectory method provide about the same compression?

Entries added to a zip file via the AddDirectory() method go through the same code path when the zip archive is written, as entries added via AddFile(). The file data is compressed, then optionally encrypted, then written to the zip file.


an unsolicited tip: you don't need to do:

zip.AddProgress += new EventHandler<AddProgressEventArgs>(Zip_AddProgress);   

you can just do:

zip.AddProgress += Zip_AddProgress;   


how are you determining that no compression is occurring?

If you are curious about the compression on each entry, you can register a SaveProgress event handler. The SaveProgress event is fired at various times during the writing of an archive, including when saving begins, when DotNetZip begins writing the data for one entry, at various intervals during the writing of one entry, after finishing writing the data for each entry, and after finishing writing all data. These stages and described in the ZipProgressEventType enumeration. When the EventType is Saving_AfterWriteEntry, you can calculate the compression ratio for THAT particular entry.

To verify that compression is not occurring, I'd suggest that you register such a SaveProgress event and look at that compression ratio.

Also, as described above, some file types cannot be compressed. JPG, MPG, MP3, ZIP files, and others are not very compressible.


Finally, doing a backup may be lots easier to do if you just use the DotNetZip command-line tool. If all you want to do is backup a particular directory, you could use the command line tool (zipit.exe) and avoid writing a program. With the zipit.exe tool, if you use the -v option, the tool prints progress reports, and will display the compression for each entry, via the mechanism I described above. Even if you prefer to write your own program, you might consider using zipit.exe to verify that compression is, or is not, occuring when you use DotNetZip.

这篇关于压缩问题,在DotNetZip大的存档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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