0

I have code like this:

#include <libzip/zip.h>

void main()
{
    int err;
    struct zip* zip_file = zip_open("some_file.zip", 0, &err);

    struct zip_file* file_in_zip = zip_fopen_index(zip_file_, 0, 0);

    char buff[1024];
    std::ofstream exctracted("extracted_data");
    while((readed = zip_fread(file_in_zip, buff, 1024)) > 0)
    {
         exctracted.write(buff, readed);
    }

    zip_close(zip_file);
}

And what if I have not file on filesystem (like some_file.zip), but only std::istream instead? How to get struct zip* object without saving stream to filesystem? I see to the documentation of libzip, but can`t find out how to do that.

  • Zip can't do seek on a stream – stark Nov 29 '19 at 12:45
  • I'm not terribly familiar with libzip, but after reviewing the documentation I don't think there is a way you can accomplish what you seek. When faced with similar circumstances in the past (zipping to memory and back vs a file and back) I've resorted to using zlib and their minizip contrib, with custom source objects to perform in-memory ops rather than the default filesys ops. If libzip can do this too, great (because you can wire it to any source/sink you want. I couldn't find it but your luck may fare better). If not, you may have to resort to a different toolkit. – WhozCraig Nov 29 '19 at 12:56

0 Answers0