0

I do not understand how this library works and the documentation is one of the worst I've ever seen. How can I read text files stored inside the archive into memory? Am I even using the right functions?

        // 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);
  • Any library that pairs up `foo_new` with `foo_free` is indeed deeply suspect. It's either `foo_alloc/foo_free` or `new/delete`. – MSalters Mar 15 '21 at 12:32
  • A lot of sources point to this library as the definitive unarchiver for C++, which pushes me to think I am just missing something – Andriy Sultanov Mar 15 '21 at 12:56

0 Answers0