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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:06:34  来源:igfitidea点击:

zip and unzip file c++

c++linuxzipunzip

提问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

I suggest zlib, it's in C but is heavily tested, used for years, and it's portable almost on every platform that you can imagine.

我建议zlib,它是用 C 语言编写的,但经过了大量测试,使用了多年,并且它几乎可以在您可以想象的每个平台上移植。

回答by Greg Hewgill

If you want a higher-level way of doing this, you can call the zipand unzipcommands directly from C++ using system()(or other process-starting mechanism). These utilities are available by default in Ubuntu.

如果您想要一种更高级别的方式来执行此操作,您可以使用(或其他进程启动机制)直接从 C++调用zipunzip命令system()。这些实用程序在 Ubuntu 中默认可用。

回答by Hot Licks

It's not terribly hard to write your own unzip logic (using zlib for decompression). (I''ve done this.) Writing zip would be a bit more difficult but doable.

编写自己的解压缩逻辑(使用 zlib 进行解压缩)并不是非常困难。(我已经这样做了。)编写 zip 会有点困难但可行。

The zip spec is online here.

zip 规范在这里在线。

回答by Adam Rosenfield

Try libzip. I haven't used it, but it looks like it presents an API very similar to the stdio API for accessing compressed files within ZIP archives.

试试libzip。我没有使用过它,但看起来它提供了一个与 stdio API 非常相似的 API,用于访问 ZIP 档案中的压缩文件。

回答by Gregory Pakosz