Actually libzpaq has an API in C++ supporting generic stream compression. You extend two abstract base classes Reader and Writer with get() and put() methods for byte I/O (and optionally read() and write() for faster block I/O), and also an error handling callback function. The compressor supports 3 basic compression levels, but not any of the really fast methods used in the zpaq archiver. All the documentation is in libzpaq.h. You include libzpaq.h and link it to libzpaq.cpp. Here is a simple program that compresses from stdin to stdout at level 2 (of 3).
Code:
#include "libzpaq.h"
#include <stdio.h>
#include <stdlib.h>
void libzpaq::error(const char* msg) { // print message and exit
fprintf(stderr, "Oops: %s\n", msg);
exit(1);
}
class In: public libzpaq::Reader {
public:
int get() {return getchar();} // returns byte 0..255 or -1 at EOF
} in;
class Out: public libzpaq::Writer {
public:
void put(int c) {putchar(c);} // writes 1 byte 0..255
} out;
int main() {
libzpaq::compress(&in, &out, 2); // level may be 1, 2, or 3
}
The decompresser would use libzpaq::decompress(&in, &out);
The documentation describes more advanced uses such as custom compression algorithms written in ZPAQL, attaching external preprocessors, and archive handling functions such as grouping and naming files and computing and verifying SHA-1 checksums. On x86 and x86-64 machines in Windows and Linux, the ZPAQL is translated to machine code and executed when compression starts as an optimization. Compile with -DNOJIT on other platforms.
You can also use the zpaqd program as a single file compressor at levels 1, 2, or 3:
zpaqd c 2 archive input
zpaqd d archive output
If you want to test zpaq this way:
zpaq a archive.zpaq input -method 1 -until 0
zpaq x archive.zpaq input -to output -force
Method can be 1 (fastest) to 6 (best). -until 0 will overwrite archive.zpaq. -force will overwrite output.