如何在视觉工作室中使用C++解压缩压缩文件 (.zip)
How to unzip a zipped file(.zip) using C++ in visual studio
我正在做一个C++项目,需要解压缩功能。
我在互联网上搜索并发现 zlib 可能有用,但事实证明zlib只提供 C 语言版本,而C++版本仅适用于 Linux。
我还发现MSDN有自己的API:解压缩和压缩功能,但是在我尝试解压缩功能解压缩压缩文件后,我发现MSDN">解压缩"功能仅对由他们自己的MSDN"压缩"功能压缩的文件有用。
换句话说,如果我有一个.zip
文件,我无法使用 MSDN API 来解压缩它。
希望有人有任何想法来帮助我,非常感谢!!
你试过libzip吗?下面是一个示例。你还应该从Github找到一些包装器,比如libzippp。
bool unzip(const std::wstring &zipPath, const std::wstring &desPath)
{
int err;
struct zip *hZip = zip_open_w(zipPath.c_str(), 0, &err);
if (hZip)
{
size_t totalIndex = zip_get_num_entries(hZip, 0);
for (size_t i = 0; i < totalIndex; i++)
{
struct zip_stat st;
zip_stat_init(&st);
zip_stat_index(hZip, i, 0, &st);
struct zip_file *zf = zip_fopen_index(hZip, i, 0);
if (!zf)
{
zip_close(hZip);
return false;
}
std::vector<char> buffer;
buffer.resize(st.size);
zip_fread(zf, buffer.data(), st.size);
zip_fclose(zf);
// your code here: write buffer to file
// desPath
// st.name: the file name
}
zip_close(hZip);
}
return true;
}
相关文章:
- 使用C++进行运行长度解压缩
- C++ 如何将数组值解压缩为函数参数
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 在 Qt(C++) 中使用 QProcess 解压缩 - 提取目录问题
- 浏览压缩文件与游览解压缩它们
- 如何在C++向量中解压缩多个值
- 解压缩 C 样式数组以及C++中的参数包
- 如何在 cpp 中解压缩数字,如果它们是使用 struct.pack(fmt, v1, v2, ..) 打包在 pyth
- 如何使用 Poco::ZIP 压缩/解压缩 zip 文件
- 在编译时解压缩数组扩展数据块 (C++11/14)
- 使用 RtMidi 解压缩 Midi 时间码
- 将参数包解压缩到 std::initializer_list?
- 解压缩可变模板参数
- 解压缩附加的压缩字符串
- 随时随地压缩/解压缩数据
- Zlib 压缩/解压缩 C++ Linux
- Gzip 压缩/解压缩长字符数组
- 编写C++程序压缩/解压缩数据
- 压缩/解压缩内存中的数据
- 如何在VS2013中压缩/解压缩文件夹