zeroturnaround / zt-zip

ZeroTurnaround ZIP Library
http://www.zeroturnaround.com/
Apache License 2.0
1.38k stars 252 forks source link

How to get Progress of Zipping and Unzipping the single file(not the folder) ? #116

Open AAChartModel opened 5 years ago

AAChartModel commented 5 years ago

In your zt-zip command line progress bar demo, I can see the method to get the progress of zipping a folder

     ZipUtil.pack(tmpDir, zipArchive, new NameMapper() {
            @Override
            public String map(String name) {
                progress.add(name);
                String progressStr = generateProgressStr(progress, 30);
                // the carriage return will return the cursor to the
                // start of the line
                System.out.print("|"+progressStr+"\r \n");
                return name;
            }
        });

It can show the progress zipping the folder properly.

However , in the to be unzipped file, we do not have the interface NameMapper just like the to be unzipped folder, what should I do to get the progress of unzipping file correctly?

toomasr commented 5 years ago

There is a public static void unpack(File zip, File outputDir, NameMapper mapper) method that you can use. Will this work for you?

AAChartModel commented 5 years ago

This method is useful for the folder but not the single file which do not have the son file!

toomasr commented 5 years ago

Do you make up an example archive structure that you are trying unpack?

AAChartModel commented 5 years ago

The other approach would be to do it based on how many bytes of the total bytes to be compressed have been processed.

Is there any method to implement this ambition?

AAChartModel commented 5 years ago

I'm using a file number approach. I have a 100 files and I show the percentage based on how many files have been processed.

As we can see, in your command line progress demo, you've solved the problem of getting folder compression progress by the first method.

The other approach would be to do it based on how many bytes of the total bytes to be compressed have been processed.

But the second method which can be used to get the progress of processing single file is not implemented in your demo.

What should I do to implement your another approach?

toomasr commented 5 years ago

This requires already some more work. I would start from the ZipUtil.iterate method and go down the rabbit hole. It takes a ZipEntryCallback. One of the implementation is FileUnpacker. If you check the logic there and see how the bytes are copied then you can write your own implementation where based on the buffer size you can calculate the file progress. This already requires some coding on your side and not just connecting APIs.

lamster2018 commented 4 years ago

same question, why not support this action? It is very useful for developer.