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
634 stars 116 forks source link

[Feature Request]: nice api for ArchiveExtractCallback/ISequentialOutStream #122

Open RScherzer opened 1 year ago

RScherzer commented 1 year ago

Feature description

Would be great if there would be an easy, clean interface in 4.x for adding a callback which is able to work on the currently decompressed block of data, so you can e.g. calculate the sha1 hash value of a file while it is being decompressed blockwise to memory. In 7z sdk theory this is an archive Extract call in test mode with ArchiveExtractCallback + ISequentialOutStream specified which inits the hash calculation, doing the hash update during the streams write calls and finalizing the hash when the extractcallback does its SetOperationResult.

Additional context

No response

Code of Conduct

rikyoz commented 1 year ago

Hi! Sorry for the late reply!

Would be great if there would be an easy, clean interface in 4.x for adding a callback which is able to work on the currently decompressed block of data, so you can e.g. calculate the sha1 hash value of a file while it is being decompressed blockwise to memory.

I think it would be a great feature indeed, I will definitely add it to the library. Thanks for the suggestion!

In 7z sdk theory this is an archive Extract call in test mode with ArchiveExtractCallback + ISequentialOutStream specified which inits the hash calculation, doing the hash update during the streams write calls and finalizing the hash when the extractcallback does its SetOperationResult.

Yeah, I need to find out the best API for providing the feature. I have some ideas which I need to test out.

I consider the v4.0 feature complete, so I'll probably add this feature to the next v4.1.

RScherzer commented 1 year ago

I've implemented it myself already (not worth or already nice enough for a pull request).

Generally I've added 2 callbacks to bitAbstractArchiveHandler

So when I want to calculate a sha1 from a single compressed file, I set up the 2 callbacks. The GetStream one setups a new ISequentialOutStream which calls the sha1 update in its write method and the sha1 finalize is called in the SetOperationResult callback. To trigger the callbacks I do a single entry test operation after setting up the callbacks.

As I said...not yet in an api-nice way, but functional ;-)

Having the stream-replace callback I will be able to solve my "give the decompressed files different names", too.

Thanks for your support!