如何解压缩已加载到 C 内存中的 zip 文件? [英] How to unzip a zip file already loaded in memory in C?
问题描述
我正在编写一个服务器,它从客户端接收一个 zip 文件,然后解压缩该文件.收到 zip 文件后,我将其存储到内存中.
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.
我找到并尝试了一些库来上传 zip 文件,例如 zlib 和 minizip,但所有这些都解压缩了磁盘上存在的文件,而不是内存中.
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.
如何从内存中解压文件?我在 Windows 上编写 C 和 C++.
How to unzip a file from memory? I write C and C++ on Windows.
推荐答案
看一看 libarchive支持zip格式.
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));
这篇关于如何解压缩已加载到 C 内存中的 zip 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!