c++ - 在 C++ 中从 zip 文件写入文件
问题描述
我需要用 C++ 解压缩从 Internet 下载的文件。我已经搜索了几个小时,但找不到任何东西。
目前我正在使用 libzip,并且可以成功读取该文件,但我只是不知道如何将其作为文件夹中的文件写入:
int unzipFile(std::string zipPath) {
//Open the ZIP archive
int err = 0;
zip* z = zip_open(zipPath.c_str(), 0, &err);
//Search for the file of given name
const char* name = "AvaloniaLauncher.exe";
struct zip_stat st;
zip_stat_init(&st);
zip_stat(z, name, 0, &st);
//Alloc memory for its uncompressed contents
char* contents = new char[st.size];
//Read the compressed file
zip_file* f = zip_fopen(z, name, 0);
zip_fread(f, contents, st.size);
zip_fclose(f);
//And close the archive
zip_close(z);
//Do something with the contents
printf(contents);
//delete allocated memory
delete[] contents;
return err;
}
我只在 12 年的旧线程上找到了这个片段,所以我不会再唤醒它。
我现在有了文件的未压缩内容,但是我将如何编写它呢?谢谢。
解决方案
推荐阅读
- c# - 编辑实体时无法轻松将属性设置为 Null
- javascript - 用于删除 URL 第一部分中的文本的书签
- php - Symfony 3.4 - 带有 ChoiceType 的 PropertyAccessor 异常
- python - 如何在python中的特定数组索引处将2个列表拼接在一起
- c# - 如何在 asp.net Visual Studio 2017 中为多活动结果集添加连接字符串 web.config
- php - 如何在 PHP 中创建一个打印 HTML 字符串的增量循环?
- objective-c - Objc 可见字符串枚举但不是 RawRepresentable
- java - 我如何找到数组中的下一个最大数?
- c++ - 使用同一对象时,asio 程序中的 Boost 线程会使所有内容崩溃
- kotlin - 如何使用 kotlin 以优美的方式编写 null 条件?