30

I want to be able to zip files from my non-gui C/C++ application, on several versions of Windows, Linux/Unix, and MacOS.

The user will compile and run using this app using Eclipse + makefile or VisualStudio. I don't want the user to have to install something separately, or have my makefile install executables.

Prefer open-source. I'm already looking at "Zip 3.0"...

  • 6
    Presumably by 'zip' you meant zip and not just compress/archive? Most of the answers here recommend zlib but according to its web site zlib alone does not support zip archives http://www.zlib.net/zlib_faq.html#faq11 – Ben L Dec 01 '09 at 14:53

8 Answers8

12

Take a look at Libarchive. I spent a lot of time seeking for a cross-platform and LGPL licensed library with convenient interface. This the best of all I've seen. Very easy and powerful tool. Originally designed for Unix-like systems but there's also the Windows version.

JWWalker
  • 22,385
  • 6
  • 55
  • 76
Dmitry
  • 3,063
  • 2
  • 22
  • 32
  • Nice find. Thanks for sharing. Great documentation. – Homer6 Mar 05 '13 at 04:10
  • Can you please help me on the installation of libarchive, I'm currently using VS2013 and I'm getting this error `MSB6006: "cmd.exe" exited with code -1073741571.`, when I *Rrebuild Solution* the generated `libarchive.sln` after following [these steps](https://github.com/libarchive/libarchive/wiki/BuildInstructions#windowsvisual-studio). – ABCmo Mar 21 '14 at 01:16
  • Sorry, I'm afraid I can't help, I don't have any machine runnning Windows available right now. I'd suggest to ask libarchive devs to help with it. – Dmitry Mar 21 '14 at 06:25
  • libarchive doesn't work with RAR files (or better it is fundamentally broken) - hence not sure how much valuable it is given how many RAR files are around the net... – Emanuele Feb 08 '21 at 11:21
9

I've had great results with miniz: https://code.google.com/p/miniz/

For a simple compression of strings in c++, I also really like Timo Bingmann's solution.

Homer6
  • 15,034
  • 11
  • 61
  • 81
  • Another vote for miniz. Nice single-file library. Got decompress of .zip archive working quickly. – M Katz Jul 17 '15 at 18:40
8

I'd recommend ZipLib https://bitbucket.org/wbenny/ziplib/wiki/Home

Personal reasons why I love this project:

  • built around c++11 stl streams (ex. decompresses into stl streams!)
  • lightweight (no dependencies other than zlib)
  • can be used on both windows & liunx

It took me a long time to find this project - hope this helps someone.

dk123
  • 18,684
  • 20
  • 70
  • 77
  • Can't see how I open a ZIP archive which I got in a memory buffer. Or on disk in WinNT, 'koz filename would be in std::wstring and there're no APIs to take it. – hypersw Feb 18 '15 at 22:25
6

We've used zlib a couple times here. It's a fairly standard library that has implementations in most main languages.

Herms
  • 37,540
  • 12
  • 78
  • 101
  • 7
    I don't think zlib can create a ZIP archive that includes multiple files. It's a compression library, and also includes functions to create one file (in the manner of gzip). – Marc Rochkind Apr 17 '15 at 16:04
4

How about this:

http://zziplib.sourceforge.net/

BastiBen
  • 19,679
  • 11
  • 56
  • 86
1

http://www.info-zip.org/UnZip.html

HTH

plan9assembler
  • 2,862
  • 1
  • 24
  • 13
1

Others have mentioned zlib, which is nice and fairly easy.

The 7-Zip (LZMA) SDK is more complex but also has very nice compression rates.

Edit: Although still in development, with the release process and history over time, I would be hesitant to recommend this now.

Kris Kumler
  • 6,307
  • 3
  • 24
  • 27
  • From the documentation it seems like it supports only archives in 7z format. Is this untrue? – pqnet Aug 30 '13 at 12:25
  • @pqnet - I use 7zip. It works with any compression format (zip, 7zip,. pkzip, tar, ... etc, etc) I cannon recommend the API at this time as I have not used it, but the 7zip apps work great. – ryyker Jul 21 '14 at 00:19
0

ZLIB - the most portable library in the world. open source, very proven and reliable. The gold standard. why use anything else?

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 27
    ... because it doesn't handle *zip files*? It just handles stream compression. – BastiBen Mar 30 '10 at 14:22
  • 7
    In the controb/minizip directory there are zip utilities. – Cheeso Mar 30 '10 at 14:52
  • 2
    @Cheeso I think you should have mentioned that. I didn't realize minizip was included with zlib, besides there's a lot of other goodies in 'contrib'. So, I sort of feel you could edit your answer to be a little more helpful. – leetNightshade Apr 03 '13 at 02:56
  • 5
    I did mention it... in my comment of three years ago! – Cheeso Apr 03 '13 at 03:14