SaveProgress question

May 25, 2010 at 9:23 AM

I'm using SaveProgress right now to get the OVERALL percentage of the entire zip process.  It works, however, it seems that SaveProgress only report each file.

How can I make it report the overall bytes? Each time I add a file, do I need to get the length and manage a "overall" length for all of the files I add?

Here is my code:

        void zFile_SaveProgress(object sender, SaveProgressEventArgs e) {
            if (e.TotalBytesToTransfer != 0 && e.BytesTransferred != 0) {
                pTracker.BytesTotal = e.TotalBytesToTransfer;
                pTracker.BytesLeft = e.BytesTransferred;
                pTracker.PercentLeft = Convert.ToInt32((pTracker.BytesLeft * 100 / pTracker.BytesTotal));

May 25, 2010 at 9:17 PM
Edited May 25, 2010 at 9:17 PM

The ZipFile class, on which the SaveProgress event hangs, in the general case, does not "know" the size of any entry (either compressed or uncompressed) until the entry is saved.   Sometimes, maybe most of the time, the entry is sourced from a filesystem file, in which case it would be easy to determine the length of the file.   Sometimes though, the entry comes from a stream, and the length of the stream is not known, and cannot be known, until it is read.  So there is no general, correct way for the ZipFile class to "know", before the Save completes, how many bytes will be read and compressed as part of the Save.  Do you see?    

If you have the situation where all of the entries in your ZipFile are filesystem files, then YES, you can keep track of that yourself and update a progress bar with that information.  But ZipFile does not do that for you.

I can imagine a modification to ZipFile where it provides what you want, if all of the entries are filesystem files. That would be convenient, I imagine.  But today it does not do that.


May 25, 2010 at 9:17 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.