Reporting progress of compression

Progress Event Handler

The compression process may take a long time especially if the data size is huge. For zip archive, there is a CompressionProgressed event to stay posted. This event relies on ProgressEventArgs which contains the number of proceeded bytes so far. This is how we can subscribe to this event using lambda extression:

1entry.CompressionProgressed += (s, e) => { 
2   Console.WriteLine(string.Format("{0} bytes compressed", e.ProceededBytes); 
3};

Reporting Zip Progress Percentage

Each time the CompressionProgressed event raises we divide the ProceededBytes number by the length of the original file. Such we find the ratio of compressed bytes at the moment. Here is the full sample.

Reporting 7z Progress Percentage

Similar approach is for 7z archive. Its entry has own CompressionProgressed event

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.