Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

zip archive processing for Cocoa - iPhone and OS X

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README
Introduction
This is a simple class for compressing and extracting files. It works depend on minizip, which is a open source zip format library.

The major class name is ZipArchive, it’s easy to use, you can declare a instance and call initialize functions, and then call addFileToZip or UnzipFileTo to finish compression or uncompression.

Details
Usage: Add all the files to you project, and and framework libz.1.2.3.dylib.

include ZipArchive.h using #import "ZipArchive/ZipArchive.h"

To create and add files to a zip

    BOOL ret = [zip CreateZipFile2:l_zipfile];
    // OR
    BOOL ret = [zip CreateZipFile2:l_zipfile Password:@"your password"]; //
    //if the Password is empty, will get the same effect as [zip CreateZipFile2:l_zipfile];

    ret = [zip addFileToZip:l_photo newname:@"photo.jpg"];
    if( ![zip CloseZipFile2] )
    {
      // error handler here
    }
    [zip release];
                
                
Extract files in a zip file to special directory, if the directory does not exist, the class will create it automatically. also if you pass ‘overWrite’ as ‘YES’ it will overwrite files already exist. You can also implement the methods of ZipArchiveDelegate to give more choices for overwriting.


Example


ZipArchive *za = [[ZipArchive alloc] init];
if ([za UnzipOpenFile: @"/Volumes/data/testfolder/Archive.zip"]) {
    BOOL ret = [za UnzipFileTo: @"/Volumes/data/testfolde/extract" overWrite: YES];
    if (NO == ret){} [za UnzipCloseFile];
}
[za release];




within your header class adopt the <ZipArchiveDelegate> protocol 

and implement these delegate methods in implementation
                
                
#pragma mark ziparchive delegate methods
-(void) ErrorMessage:(NSString*) msg{
    ENTER_METHOD;
}
-(BOOL)OverWriteOperation:(NSString*) file{
    return YES;
}

//optional
-(void) UnzipProgress:(uLong)myCurrentFileIndex total:(uLong)myTotalFileCount{
    ENTER_METHOD;
}
    
    
#define ENTER_METHOD NSLog(@">> %s", __func__)     


           
Something went wrong with that request. Please try again.