Skip to main content
Email Password   helpLost your password?

Introduction

The Crypto++ library is a freeware library of cryptographic schemes, written by Wei Dai. However the library also contains other useful classes which are not immediately apparent when you use the library. Two of these are the Gzip and Gunzip classes which can be used to compress and decompress (zip and unzip) data.

Compression

Compressing your data could not be simpler. Say you had data pData that was of size dwLen that you wished to compress.

#include <gzip.h>


Gzip zipper(1);    // 1 is fast, 9 is slow


  zipper.Put(pData,dwLen);
  zipper.Close();

  byte* pCompressed = new byte[zipper.MaxRetrieveable()];
  zipper.Get(pCompressed,zipper.MaxRetrieveable());

pCompressed now contains the compressed data.

Decompression

You may not be surprised to know that decompression is just as easy. (dwLen is now the length of our compressed data)

Gunzip unzipper;

  unzipper.Put(pCompressedData,dwLen);
  unzipper.Close();

  byte* pData = new byte[unzipper.MaxRetrieveable()];
  unzipper.Get(pData,unzipper.MaxRetrieveable());

pData now contains the uncompressed data.

Remarks

Thanks to Wei Dai for his permission to write this article in what is hoped to be a series of articles on the use of his Crypto++ library.

Latest versions

The latest versions of the Crypto++ library can be found here.
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Questionpassword protected archive? Pin
Matthias Blum
14:23 15 Jan '09  
AnswerRe: password protected archive? Pin
Shaun Wilde
1:06 16 Jan '09  
GeneralCompressing and Decompressing Data using C++ Pin
jassshan
22:39 24 Nov '08  
GeneralGzip a set of files Pin
sheyliger
4:21 7 Jul '08  
GeneralRe: Gzip a set of files Pin
Shaun Wilde
9:35 7 Jul '08  
GeneralWell I've added header but it doesn't work Pin
Noagene
22:36 15 Aug '07  
GeneralRe: Well I've added header but it doesn't work Pin
Shaun Wilde
0:28 19 Aug '07  
GeneralRe: Well I've added header but it doesn't work Pin
Noagene
14:38 19 Aug '07  
GeneralError code has been changed.. Pin
Noagene
19:55 19 Aug '07  
AnswerRe: Error code has been changed.. Pin
butuzov_Ilya
23:27 6 Sep '07  
GeneralClose() is No Longer Available... Pin
Jeffrey Walton
16:21 27 May '07  
GeneralRe: Close() is No Longer Available... Pin
Shaun Wilde
11:04 28 May '07  
GeneralRe: Close() is No Longer Available... Pin
Jeffrey Walton
12:03 28 May '07  
GeneralRe: Close() is No Longer Available... Pin
Shaun Wilde
20:55 29 May '07  
GeneralRe: Close() is No Longer Available... Pin
Jeffrey Walton
12:08 28 May '07  
GeneralRe: Close() is No Longer Available... Pin
Shaun Wilde
20:56 29 May '07  
GeneralCrypto++ Integration Article Pin
Jeffrey Walton
19:28 8 Dec '06  
GeneralGzip work verry greatly! Pin
dungbkhn
18:50 28 Jun '05  
GeneralGot a wrong result! Pin
JerryCheng
23:44 11 Nov '03  
GeneralRe: Got a wrong result! Pin
Shaun Wilde
9:13 12 Nov '03  
GeneralRe: Got a wrong result! Pin
JerryCheng
17:59 13 Nov '03  
GeneralRe: Got a wrong result! Pin
Shaun Wilde
5:43 14 Nov '03  
Generalencryption of file..help?? Pin
xxhimanshu
21:40 11 Nov '03  
GeneralRe: encryption of file..help?? Pin
Shaun Wilde
9:17 12 Nov '03  
Generalzipping Pin
Anonymous
9:24 1 Jun '03  


Last Updated 16 Apr 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009