Linux 压缩和解压缩文件 C++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12011723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
zip and unzip file c++
提问by hakuna matata
I want to write code that zips a folder to a .zip file, or unzips a .zip file into a folder. I believe I need some library that supports it, am I right? If so, is there a specific library I should use? I want to write the code in C++ on a Linux machine (Ubuntu). Thanks for the help.
我想编写将文件夹压缩到 .zip 文件或将 .zip 文件解压缩到文件夹中的代码。我相信我需要一些支持它的库,对吗?如果是这样,我应该使用特定的库吗?我想在 Linux 机器(Ubuntu)上用 C++ 编写代码。谢谢您的帮助。
采纳答案by π?ντα ?ε?
I would recommend the LZMA/7 Ziplibrary. It supports a broad variety of compression formats and is usable for almost any kind of (OS) environment. The library API is in C and you can just pick what you need for your purpose (just decompression, compression or both) easily. It's also coming with an open source license that makes it easy to use in any kind of project (commercial or OS).
我会推荐LZMA/7 Zip库。它支持多种压缩格式,几乎可用于任何类型的 (OS) 环境。库 API 是 C 语言,您可以轻松选择您需要的内容(只是解压、压缩或两者兼有)。它还附带一个开源许可证,使其易于在任何类型的项目(商业或操作系统)中使用。
We're using this library in a number of embedded projects successfully.
我们在许多嵌入式项目中成功地使用了这个库。
回答by user827992
回答by Greg Hewgill
If you want a higher-level way of doing this, you can call the zip
and unzip
commands directly from C++ using system()
(or other process-starting mechanism). These utilities are available by default in Ubuntu.
如果您想要一种更高级别的方式来执行此操作,您可以使用(或其他进程启动机制)直接从 C++调用zip
和unzip
命令system()
。这些实用程序在 Ubuntu 中默认可用。
回答by Hot Licks
回答by Adam Rosenfield
回答by Gregory Pakosz
Have a look at Rich Geldreich's miniz.