如何使用 C++ 中的 LibArchive 在内存中解压缩存档?

问题描述

我不明白这个库是如何工作的,而且文档是我见过的最糟糕的文档之一。如何将存档中存储的文本文件读取到内存中?我是否使用了正确的功能

        // Reading the raw zip file into memory
        std::ifstream raw_file("archive.zip",std::ios::binary);
        auto buffer = static_cast<std::ostringstream&>(
                  std::ostringstream{} << raw_file.rdbuf())
                  .str();

        struct archive* a = archive_read_new();
        struct archive_entry* entry;
        archive_read_support_compression_all(a);
        archive_read_support_format_raw(a);
        int r =
            archive_read_open_memory(a,buffer.data(),buffer.size());
        while (archive_read_next_header(a,&entry) == ARCHIVE_OK) {
            archive_read_data(a,buffer.size());
        }

        // This prints out binary data instead of text files stored inside the archive
        std::cout << buffer << std::endl;
        r = archive_read_free(a);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)