### Two classes for doing Gzip in memory!

This article was contributed by Gao dasheng.

Environment: OS independend

Now many applications need API to do gzip in memory. Zlib form http://www.gzip.org/zlib provides gzip and ungzip function,but they is for file,It's very inconvenience to compress and decompress small data compressing in memory. I ported the gzip and ungzip function to two template class CA2GZIP and CGZIP2A to do gzip in memory, and they also allocate and deallocate memory automatically. It works with zlib from http://www.gzip.org/zlib. the following is some codes 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 irectly
    		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 - 142 Kb
Download source - 142 Kb

### History

Date Posted: Jun 20, 2003]