问题
I am writing a server, which receive a zip file from client, and unzip the file. When I receiving the zip file, I store it into memory.
I find and try some library to upzip a zip file, such zlib and minizip, but all of them unzip a file exists on disk, not from memory.
I don't want to save the file into disk temperorily and extract it, it's not efficient.
How to unzip a file from memory? I write C and C++ on Windows.
回答1:
zlib supports in-memory inflate() and deflate() functions. You can read how from here
回答2:
Take a look at libarchive It supports the zip format.
Example of extracting archive in memory:
struct archive *a = archive_read_new();
archive_read_support_compression_gzip(a);
archive_read_support_format_tar(a);
r = archive_read_open_memory(a, buff, sizeof(buff));
回答3:
libzip (which is based on zlib) has a function to open an archive from memory. Example code is on github.
src = zip_source_buffer_create(data, size, 1, &error)
za = zip_open_from_source(src, 0, &error)
来源:https://stackoverflow.com/questions/10781693/how-to-unzip-a-zip-file-already-loaded-in-memory-in-c