I'm trying to read a .zip file using libarchive but I'm getting the following error in archive_read_data ()
Unsupported ZIP compression method (deflation)
The same error occurs with all other compression formats.
follow the code:
archive* a;
archive_entry* entry;
a = archive_read_new();
assert(a != NULL);
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
int result = archive_read_open_filename(a, "Data.zip", 0);
if (result != ARCHIVE_OK) {
std::cerr << archive_error_string(a) << std::endl;
return 1;
}
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
auto file_size = archive_entry_size(entry);
std::cout << archive_entry_pathname(entry) << ", size: " << file_size << std::endl;
auto buffer = new char[file_size];
auto read_result = archive_read_data(a, buffer, file_size);
if (read_result <= 0) {
std::cerr << archive_error_string(a) << std::endl;
return 1;
} else if (read_result > 0) {
std::ofstream file(archive_entry_pathname(entry), std::ios::binary);
file.write(buffer, file_size);
file.close();
}
delete[] buffer;
}
archive_read_finish(a);
What am I doing wrong?