★ wanayoo — archive 1999 http://codeguru.developer.com/cpp_mfc/czip.shtmlNouvelle recherche | Portail wanayoo
EarthWeb
Developer.com Click Here!
Click Here!
Find:
 

EXPERT SEARCH
SEARCH THE IT WEB -----
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Contest
mfc codeguru
submission guidelines
 
Book
thinking in c++
stl programmer's guide
reviews
 
Interact
forums
newsgroups
guest book
jobs
jokes
open faq
what's new
 
Other
about
links
newsletters
privacy
tools
 

-----
Visual C++ by E-mail:

Get the weekly e-mail highlights on
Visual C++!
-----



EarthWeb Sites:
IT Management
Networking & Telecommunications
IT Jobs
Software Development
Hardware & Systems
Commerce
Community

EarthWeb Worldwide

   

CZip/CUnzip classes for zipping and unzipping files


This article was contributed by Florent Jugla.

Environment: Win98, VC 5.0

This article describes classes to zip and unzip files.  The classes use the gzip GNU source code (gzip-1.2.4a).  This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.  See the file COPYING included in the source code.

The target DLL exports two classes:

  • CZip (for zipping files)
  • CUnzip (for unzipping files)

Description:

A CZip or CUnzip object is built with a file name.  Then, the SwapSize() method must be called on that object (with one argument which is the target file name) in order to zip/unzip the file.  SwapSize() may throw a CZipException exception.  A message bound to the exception can be retrieved using the GetString() method.  Exceptions are thrown when:

  • the source file does not exists or cannot be opened for reading
  • the target file cannot be created (for example, this file already exists)
  • the gzip code is returns an error;  in this case, the message bound to the exception contains the message returned by the gzip source code via stderr

To use CZip or CUnzip, do the following:

  1. include czip.h in your project
  2. link your project with zipdll.dll using zipdll.lib
  3. move zipdll.dll to the same directory as your executable
    Note:  You can also dynamically link to zipdll.dll (I haven't tested that, though).

Here's an example of how to zip a file:

  try
  {
    CZip myFileToZip ("file_to_zip_name");
    myFileToZip.SwapSize ("file_zipped_name"); 
  } 
  catch (CZipException e) 
  {
    cout << "problem while zipping : " << e.GetString() << endl;
    delete pExcep; 
  } 

Notes:

  1. The CZipped files can be unzipped using WinZip if its name doesn't have a ".zip" extension.  If the zipped file has a ".zip" extension, WinZip won't be able to open the file.

  2. An archive constructed with WinZip can be extracted using a CUnzip object if it contains only a single file.

  3. In order to know the error messages written by gzip code on stderr, a temp file is built and attached to stderr.  If this temp file cannot be built (no way to write to the current directory for example), the error messages from gzip code (if any) will not be known, but the zip/unzip operations can still be achieved.

Download:

CZip/CUnzip DLL source   czip_source.zip (99 KB)
Demo program   czip_demo.zip (3 KB)

Date Updated: 2 March 1999
Date Posted: 27 February 1999

Comments:

Add Comment

   

Give them a visit Click Here!

Click Here!

INSTANT EXPERTS!
Savvy IT Pros report on SupportSource. Take a look inside the largest vault of multi-vendor computing specs ever assembled. Click here for an In-depth Report,.

For tons of Windows technology resources, check out the Windows Programming directory.

Searching the Web for tech topics just got better with
TechCrawler where all results come only from popular technical sites.

WINNER!!!
Congratulations to James Hole, of New Mexico! The grand prize winner of EarthWeb's Flatten the Obstacles Sweepstakes and now a proud Hummer(R) owner.

Give them a visit Click Here!

Click Here!

Click Here!

Click Here!

Home About Us Search Subscribe Advertising Info Contact Us FAQs
Use of this site is subject to certain Terms & Conditions.
Earthweb's statement regarding our users' right to privacy.
Copyright ©1996-2000 EarthWeb Inc.. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited.