我不明白这个库是如何工作的,而且文档是我见过的最糟糕的文档之一。如何将存档中存储的文本文件读入内存?我什至使用正确的功能吗?
// 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.data(), 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);