dcsimg

Two Classes for Doing Gzip in Memory

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


Environment: OS independent

Now, many applications need API to do Gzip in memory. The Zlib form, http://www.gzip.org/zlib, provides Gzip and unGzip function, but they are for files. It's very inconvenient to compress and decompress small data that could be compressed in memory. I ported the Gzip and unGzip functions to two template classes, CA2GZIP and CGZIP2A, to do Gzip in memory; they also allocate and deallocate memory automatically. It works with zlib from http://www.gzip.org/zlib. The following is some code for how to use them.

#include "GZipHelper.h"
  void main()
  {
    char plainText[]="Plain text here";
      CA2GZIP gzip(plainText,strlen(plainText));
                                   // do compressing here;
      LPGZIP pgzip=gzip.pgzip;     // pgzip is zipped data pointer,
                                   // you can use it directly
      int len=gzip.Length;         // Length is length of zipped
                                   // data;

      CGZIP2A plain(pgzip,len);    // do uncompressing here

      char *pplain=plain.psz;      // psz is plain data pointer
      int  aLen=plain.Length;      // Length is length of unzipped
                                   // data.
  }

Downloads

Download demo project - 131 Kb


This article was originally published on July 9th, 2003

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date