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
611 stars 112 forks source link

[Feature Request]: Solid Extract to MemoryStream or List #144

Closed Kayot closed 1 year ago

Kayot commented 1 year ago

Feature description

I see a function named ExtractToList, but I am unsure on how to use it or if it does what I think it does. In the wiki it states that it's better to extract the whole archive at once if it's a solid archive. The example is for file extraction. I'd like to do this into memory.

As the wiki explained, even putting the 7zip file into memory first doesn't help with the speed.

So if it's possible to quickly extract all the files from a solid archive at once into memory, then how, and if not, is it possible to add it?

(I'm actually not sure how Func works, so pardon my ignorance)

Additional context

No response

Code of Conduct

rikyoz commented 1 year ago

Hi!

I see a function named ExtractToList, but I am unsure on how to use it or if it does what I think it does.

Uhm, this library doesn't provide an ExtractToList function.

In the wiki it states that it's better to extract the whole archive at once if it's a solid archive.

I cannot find where the Wiki states that. Maybe you're referring to some other project? Anyway, in general, that's true. Or rather, in solid archives, it's better to extract the items in the same order as they're stored; otherwise, there's a performance penalty.

As the wiki explained, even putting the 7zip file into memory first doesn't help with the speed.

I cannot find where the Wiki states that too. In general, putting the file into memory first might improve speed in some use cases, but not all, it really depends on yours.

So if it's possible to quickly extract all the files from a solid archive at once into memory, then how, and if not, is it possible to add it?

Using bit7z, it's possible using the overload of the BitFileExtractor::extract method that takes a reference to a map as an argument. Each entry in the map has the path of the file (inside the archive) as the key (string) and the corresponding extracted file content as the value (stored as a vector of bytes). For example:

Bit7zLibrary lib{ "7z.dll" };
BitFileExtractor extractor{ lib, BitFormat::SevenZip };

std::map< std::string, std::vector< byte_t > > output_map;
extractor.extract( "path/to/archive.7z", output_map );

Please note, though, that this is an example of extracting to memory buffers rather than streams, so I wonder if it's the same as what you're trying to achieve.

Kayot commented 1 year ago

My apologies. I have no idea how I ended up under this repository when I was looking at SevenZipExtractor. I'll close this question since it's under the wrong repo. Thank you and please have a good day!

rikyoz commented 1 year ago

No worries, have a good day you too!