How to compress/decompress files with Czip/cunzip class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.