Search code examples
c#sharpziplib

Using SharpZipLib and getting progress status?


How would i show the progress of compressing in SharpZipLib?
I'm developing a small application that Zip many file to a single zip file. it may got a while to be done, there might be a progress bar that shows the progress of compressing, so is there a way to know how much has been compressed in SharpZipLib?


Solution

  • Yes you can see how much is compressed, by size of output stream, but that is not enought to show a progress bar, you should also know how big a output stream would be at the end, and of course you can't know that in advance.

    You can measure progres when zipping individual files, and do that proportionaly by size of files, one file moves progress percentage by (size_of_file / total_size_of_all_files) * 100

    For example let's say that you have 3 files :

    file1.bin 1000 kb
    file2.bin 500 kb
    file3.bin 200 kb
    

    after first file compressed move progres on 59%, after second file move it by 29% to 88% and after third to 100%.