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
602 stars 110 forks source link

[Feature Request]: [BitFormat::Auto] Why not like 7zip.exe, can uncompress any format file? #155

Closed ShiverZm closed 11 months ago

ShiverZm commented 11 months ago

Feature description

i need uncompress a file of office to analyze it.but bit7z can do this but 7z.exe can.

Additional context

i use bit7z, to uncompress .docx file, but when run the code , it throws a BitException, i don t know why, it seems that just only uncompress the file that matches with which supported. Does it ?

Code of Conduct

ShiverZm commented 11 months ago

like this, but it throws BitException

int main(int argc, char* argv[]) {
    try { // bit7z classes can throw BitException objects
        using namespace bit7z;

        Bit7zLibrary lib{ "D:\\workspace\\github\\bit7z\\bin\\x64\\Debug\\7za.dll" };
        //BitArchiveReader arc{ lib, "D:\\workspace\\github\\test_bit7z\\test_office.7z", BitFormat::SevenZip };
        BitArchiveReader arc{ lib, "D:\\workspace\\github\\test_bit7z\\test_office.doc", BitFormat::Compound };

        // Printing archive metadata
        std::cout << "Archive properties" << std::endl;
        std::cout << "  Items count: " << arc.itemsCount() << std::endl;
        std::cout << "  Folders count: " << arc.foldersCount() << std::endl;
        std::cout << "  Files count: " << arc.filesCount() << std::endl;
        std::cout << "  Size: " << arc.size() << std::endl;
        std::cout << "  Packed size: " << arc.packSize() << std::endl;
        std::cout << std::endl;

        // Printing the metadata of the archived items
        std::cout << "Archived items";
        auto arc_items = arc.items();
        for (auto& item : arc_items) {
            std::cout << std::endl;
            std::cout << "  Item index: " << item.index() << std::endl;
            std::cout << "    Name: " << item.name() << std::endl;
            std::cout << "    Extension: " << item.extension() << std::endl;
            std::cout << "    Path: " << item.path() << std::endl;
            std::cout << "    IsDir: " << item.isDir() << std::endl;
            std::cout << "    Size: " << item.size() << std::endl;
            std::cout << "    Packed size: " << item.packSize() << std::endl;
            std::cout << "    CRC: " << item.crc() << std::endl;
        }
    }
    catch (const bit7z::BitException& ex) { /* Do something with ex.what()...*/ }
    return 0;
}