How to unzip a zip file already loaded in memory in C?

戏子无情 提交于 2019-12-23 02:49:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!