rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
623 stars 113 forks source link

[Feature Request]: Get extract result #85

Closed chifandeyu closed 2 years ago

chifandeyu commented 2 years ago

Feature description

Can get extract result when extract finish?

Additional context

No response

Code of Conduct

rikyoz commented 2 years ago

Hi! Could you be more specific? What do you mean by "extract result"?

chifandeyu commented 2 years ago

Sorry, I didn't describe it clearly. I want to listen to the total progress when extracting archive file. And whether the decompression is successful.

rikyoz commented 2 years ago

Sorry, I didn't describe it clearly.

No problem!

I want to listen to the total progress when extracting archive file.

You have to set both the total size and the progress size callbacks. You can use the setter functions BitExtractor::setTotalCallback and BitExtractor::setProgressCallback. E.g.:

//...
uint64_t total = 0; // We need a global total variable in order to calculate the progress percentage
extractor.setTotalCallback([this, &total](uint64_t total_size) {
    total_size = total; // It will be called only once at the start of the extraction process.
});
extractor.setProgressCallback([this, &total](uint64_t progress_size) {
    std::cout << "Extracting... " 
              << static_cast<int>( ( 100.0 * progress_size ) / total ) << "%" << std::endl;
});
//...

And whether the decompression is successful.

If the extraction function of BitExtractor finishes without throwing exceptions, it means that the decompression was successful. Otherwise, the function will throw a BitException object.

chifandeyu commented 2 years ago

Sorry, I didn't describe it clearly.

No problem!

I want to listen to the total progress when extracting archive file.

You have to set both the total size and the progress size callbacks. You can use the setter functions BitExtractor::setTotalCallback and BitExtractor::setProgressCallback. E.g.:

//...
uint64_t total = 0; // We need a global total variable in order to calculate the progress percentage
extractor.setTotalCallback([this, &total](uint64_t total_size) {
    total_size = total; // It will be called only once at the start of the extraction process.
});
extractor.setProgressCallback([this, &total](uint64_t progress_size) {
    std::cout << "Extracting... " 
              << static_cast<int>( ( 100.0 * progress_size ) / total ) << "%" << std::endl;
});
//...

And whether the decompression is successful.

If the extraction function of BitExtractor finishes without throwing exceptions, it means that the decompression was successful. Otherwise, the function will throw a BitException object.

👍That's great! Thx.