Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AAChartModel opened this issue Jan 23, 2019 · 7 comments

Comments

@AAChartModel
Copy link

AAChartModel commented Jan 23, 2019

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
Copy link
Contributor

toomasr commented Jan 23, 2019

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

@AAChartModel
Copy link
Author

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

@toomasr
Copy link
Contributor

toomasr commented Jan 23, 2019

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

@AAChartModel
Copy link
Author

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
Copy link
Author

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?

@AAChartModel AAChartModel changed the title How to get Progress of Zipping and Unzipping the file(not the folder) ? How to get Progress of Zipping and Unzipping the single file(not the folder) ? Jan 24, 2019
@toomasr
Copy link
Contributor

toomasr commented Jan 24, 2019

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
Copy link

lamster2018 commented Jan 9, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants