Vi.
Vi.

Reputation: 38772

Multi-algorithm compression library for C

I want my program to be able to use zlib, lzma, lzo and bzip2 compression algorithms.

Is there any compression library for C which simlifies working with multiple algorithms (like libmcrypt supporting multiple encryption modes and algorithms)?

Expecting something like this:

struct compressor c;
universal_compressor_init(&c, "lzma", 7 /* compression level */);
universal_compressor_compress(&c, inputbuf, inputsize, outputbuf, &outputsize);
universal_compressor_save_state(&c, statebuf, &statesize);

Note: It is not about zip/rar/7z/tar/cpio and other archive formats, it's about compression of raw buffers. Think of compressed networking protocol or about random access to compressed block device (like cloop).

Upvotes: 8

Views: 505

Answers (2)

Stefano Sanfilippo
Stefano Sanfilippo

Reputation: 33126

LibArchive fulfills your requirements.

From the introduction:

The libarchive library features:

  • Support for a variety of archive and compression formats.
  • Robust automatic format detection, including archive/compression combinations such as tar.gz. ...

EDIT: for handling raw streams (at least until they split libfilter from libarchive), consider using Boost::iostreams or libbu++ (just found on GitHub)

Upvotes: 3

Scott Jones
Scott Jones

Reputation: 2906

I recommend 7-zip (http://www.7-zip.org/sdk.html). I haven't found anything to beat it for both compression speed and size.

Upvotes: 0

Related Questions