Skip to content

ricardoquesada/ZipArchive

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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__)

About

zip archive processing for Cocoa - iPhone and OS X

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 87.0%
  • Objective-C 13.0%