Compression issue with large file archive in DotNetZip

Hello....

I am writing a backup program in C # 3.5 using the latest version of DotNetZip. The foundations of the program should be given the location on the server and the maximum size of the stretched zip file and transition. From there, it should traverse the entire folder / files from a given location and add them to the archive, preserving the exact structure. It should also compress everything to a reasonable amount. This uncompressed set of folders / files can easily be 10-25gb, while the created created files are limited to about 1gb each.

Everything works for me (using DotNetZip). My only problem is that practically nothing really happens. I decided to use the "AddDirectory" method to simplify the code and, as a rule, how well it fit my project. After reading, I second guess about this decision.

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

  • I have tried all the compression levels offered by Ionic.Zlib.CompressionLevel and none of them help. Should I consider using an external compression algorithm and transfer it to a 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(); } 

Thanks for the help!

+4
source share
3 answers

1.In the code below and the large number of files in the archive, should I compress each file since it is added to zip?

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

or should the Adddirectory method provide the same compression?

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


unsolicited advice: you do not need to do:

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

you can just do:

 zip.AddProgress += Zip_AddProgress; 

How do you determine that compression does not occur?

If you are interested in compression for each record, you can register a SaveProgress event handler. The SaveProgress event is triggered at different times during archive recording, including when saving starts, when DotNetZip starts recording data for one record at different intervals during recording one record after the data recording for each record is completed and after the end of recording all data. These steps are described in the ZipProgressEventType enumeration . When the EventType is Saving_AfterWriteEntry, you can calculate the compression ratio for a particular THAT record.

To make sure that compression does not occur, I suggest that you register such a SaveProgress event and look at the compression ratio.

In addition, as described above, some types of files cannot be compressed. JPG, MPG, MP3, ZIP files and others are not very compressed.


Finally, making a backup can be a lot simpler if you just use the DotNetZip command-line tool. If all you want to do is back up a specific directory, you can use the command line tool (zipit.exe) and not write the program. Using the zipit.exe tool, if you use the -v option, the tool prints progress reports and displays the compression for each record through the mechanism described above. Even if you prefer to write your own program, you can use zipit.exe to verify that compression occurs or not when you use DotNetZip.

+2
source

I'm not sure I underestimated your question, but the maximum size for any zip file is its 4Gb . You may need to create a new ZipFile every time you reach this limit.

Sorry if this does not help you.

+2
source

What data do you compress? Some types of data simply do not compress very well, such as JPEG, or ZIP files that are already compressed.

+1
source

Source: https://habr.com/ru/post/1337007/


All Articles