This article describes how to compress/decompress files with the Czip/cunzip class, which uses the gzip GNU Source Code (GZIP-1.2.4A). This is a free software that can be distributed and modified under the Gun general Public License (License) terms and conditions for the general Public License, please refer to:
Http://www.vckbase.com/vckbase/uniondocs/gungpl.htm
Target Dynamic Library output two classes:
Czip (for compressed files)
Cunzip (for extracting files)
First create the Czip or Cunzip object with the filename. Then, compression and decompression must call the object's Swapsize () method, which is the target filename. If the call fails, swapsize () can throw a czipexception exception. The information associated with the exception can be obtained using the Getstringt method, and the following conditions will produce an exception:
--The source file does not exist or cannot be read to open the file
-Cannot create destination file. For example, this file already exists
--gzip code returns an error, in which case the information associated with the exception contains information returned by the Gzip source code via STDERR
Czip or Cunzip are used in the following ways:
Include Czip.h files in the project
Link Engineering to Zipdll.dll with Zipdll.lib
Copy Zipdll.dll to the directory where the executable file resides
Note: You can also dynamically link to zipdll.dll (not tested). The following is an example code snippet using the Czip/cunzip class:
try
{
CZip myFileToZip ("file_to_zip_name");
myFileToZip.SwapSize ("file_zipped_name");
}
catch (CZipException e)
{
cout << "problem while zipping : " << e.GetString() << endl;
delete pExcep;
}
Note: If you want to decompress with WinZip, you cannot use ". zip" as the file name extension. Otherwise WinZip cannot open this file. A document compressed with WinZip (which can contain only one file) can be unpacked with a Cunzip object.
This article supporting source code