List Archive


Thread Index


From: Qifei Wang <>
Subject: Re: Failed to unzip file by zip_fdopen with the error code ZIP_ER_OPNOTSUPP
Date: Fri, 6 Sep 2019 19:00:44 -0700

More context: This code snippet works well in desktop unit test. The bug happens when I test it on Android. The file is downloaded from the server. The `src->supports` is recorded as 16575 while `needed_support_read` is set to 207 at the runtime which causes the bug.


Qifei Wang

On Fri, Sep 6, 2019 at 6:03 PM Qifei Wang <> wrote:
Hi there,

  I am trying to unzip a zip file from file descriptor by the following code snippet. It reports the error ZIP_ER_OPNOTSUPP. The file descriptor is valid. The error seems reported by zip_open_from_source() method. See Any idea about this?

  zip_t* archive = zip_fdopen(file_descriptor, O_RDONLY, &errorp);
  if (!archive) {
    // Error report here.

  zip_int64_t num = zip_get_num_entries(archive, ZIP_FL_UNCHANGED);
  for (zip_uint64_t i = 0; i < num; ++i) {
    const char* name = zip_get_name(archive, i, ZIP_FL_ENC_GUESS);
    zip_file_t* zip_file = zip_fopen(archive, name, ZIP_FL_ENC_GUESS);
    zip_stat_t zip_file_stat;
    zip_stat_index(archive, /*index=*/i, /*flags=*/0, &zip_file_stat);
    auto buf = absl::make_unique<char[]>(zip_file_stat.size);
    zip_int64_t size_read = zip_fread(zip_file, buf.get(), zip_file_stat.size);
    if (size_read == -1) {
      // Error handling.
    const std::string output_filename = file::JoinPath(dir, name);
    // Extract to output_filename.
    int zip_file_close_result = zip_fclose(zip_file);
    if (zip_file_close_result != 0) {
      // Error handling.
  if (zip_close(archive) != 0) {
    // Error handling.


Qifei Wang

Made by MHonArc.