Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 757
Vi. Avatar asked May 02 '13 23:05

Vi.


1 Answers

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)

like image 84
Stefano Sanfilippo Avatar answered Sep 18 '22 12:09

Stefano Sanfilippo