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:

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

Reporting 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.