zip and unzip file c++ [closed]

爷,独闯天下 提交于 2019-11-30 22:51:02

问题


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.


回答1:


I would recommend the LZMA/7 Zip library. 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).

We're using this library in a number of embedded projects successfully.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


Have a look at Rich Geldreich's miniz.




回答6:


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.

The zip spec is online here.



来源:https://stackoverflow.com/questions/12011723/zip-and-unzip-file-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!