I am attempting to extract file from a zip archive that is there in a memstream.
I’ve initialized the memstream like below:
f = open_memstream(&response_str, &size);
This is used by libcurl to write data into, set in the curl options.
curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);
I then do an fflush and fseek to 0.
fflush(f);
fseek(f, 0L, SEEK_SET);
When i print out the data in the file pointer, it seems to be printing the correct value.
I can even write its contents into a file like below:
dest_file = fopen("derivates.zip", "wb");
for (int i =0; i<size; i++) {
file_read_buffer = fgetc(f);
fprintf(dest_file, "%c", file_read_buffer);
}
This creates a zip archive that i can then open using my operating system’s installed unzip tools.
However, i want to be able to read the file contents using libzip without having to first write the contents into the file.
I was trying out something like this:
file_descriptor_f = fileno(f);
archive = zip_fdopen(file_descriptor_f, 0, &err);
However, i noticed that this doesn’t work, because the file_descriptor_f value that I get becomes -1. I suspect that since memstream is only an interface to read and write to a file in memory, there is no actual file out there and hence no valid file descriptor.
I was wondering if there was a way to read zip files using libzip using just a file pointer (FILE *f).