zlibcomplete
Simple C++ wrapper for zlib using RAII and std::string with flush.
 All Classes Namespaces Files Functions Enumerations Enumerator Macros Pages
zlibcomplete introduction

Introduction

This library provides a convenient wrapper around the zlib library. zlib is written in C and uses explicit pointers and allocation for all operations. zlibcomplete simplifies typical use by providing a high-level C++ interface using std::string instead of pointers. This library uses RAII (Resource Allocation Is Initialization) in order to obviate explicit allocation or deallocation. The result is an easier to use and simpler, less error-prone interface to the underlying zlib functionality.

Download

zlibcomplete-1.0.5.tar.gz

Installation

    ./bootstrap.sh
    autoreconf
    ./configure
    make
    sudo make install

Usage

Here is an example program showing how to do GZip compression:

    #include <iostream>
    #include <zlc/zlibcomplete.hpp>
    using namespace zlibcomplete;
    using namespace std;
    int main(int argc, char **argv)
    {
      const int CHUNK = 16384;
      char inbuf[CHUNK];
      int readBytes;
      GZipCompressor compressor(9, auto_flush);
      for (;;) {
        cin.read(inbuf, CHUNK);
        readBytes = cin.gcount();
        if (readBytes == 0) {
          break;
        }
        string input(inbuf, readBytes);
        string output = compressor.compress(input);
        cout << output;
      }
      cout << compressor.finish();
      return 0;
    }

Decompression is similar:

    #include <iostream>
    #include <zlc/zlibcomplete.hpp>
    using namespace zlibcomplete;
    using namespace std;
    int main(int argc, char **argv)
    {
      const int CHUNK = 16384;
      char inbuf[CHUNK];
      int readBytes;
      GZipDecompressor decompressor;
      for (;;) {
        cin.read(inbuf, CHUNK);
        readBytes = cin.gcount();
        if (readBytes == 0) {
          break;
        }
        string input(inbuf, readBytes);
        string output = decompressor.decompress(input);
        cout << output;
      }
      return 0;
    }

Project and Community

We are hosted on GitHub. Here is our GitHub Project Page

Want to contribute a patch, suggest a feature, or report a bug? Issue Tracker