ZipArchive Class Reference
Inherits from | NSObject |
Declared in | ZipArchive.h ZipArchive.mm |
Overview
Class for creating and unzipping ZIP files
Usage
Include
libz.dylib
to your project’s “Link Binaries with Libraries” section of the target settings.Import
ZipArchive.h
#import "ZipArchive.h"
If unzipping file, the code might look like:
NSString *subdirectory = @"archive"; // the folder name to which you will unzip the files NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *archivePath = [documentsPath stringByAppendingPathComponent:subdirectory]; ZipArchive *za = [[ZipArchive alloc] init]; if ([za unzipOpenFile:path]) { BOOL ret = [za unzipFileTo:archivePath overwrite:YES]; NSAssert(ret, @"Unzip failed"); }
See also
- This is based upon aish’s original ZipArchive class
- This includes version 1.01h of Minizip
Tasks
Properties
-
delegate
Delegate property
property
Create zip files
-
– createZipFile:
Create zip file
-
– createZipFile:password:
Create zip file with password
-
– addFileToZip:newname:
Add file to zip file
-
– closeZipFile
Close the zip file
Unzip files
-
– unzipOpenFile:
Open zip file to unzip
-
– unzipOpenFile:password:
Open zip file to unzip with password
-
– unzipFileTo:overwrite:
Unzip zip file to particular path
-
– unzipCloseFile
Close the zip file being unzipped
Instance Methods
addFileToZip:newname:
Add file to zip file
- (BOOL)addFileToZip:(NSString *)file newname:(NSString *)newname
Parameters
- file
Path of file to create
- newname
The new name of the file
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h
closeZipFile
Close the zip file
- (BOOL)closeZipFile
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h
createZipFile:
Create zip file
- (BOOL)createZipFile:(NSString *)zipFile
Parameters
- zipFile
Path of file to create.
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h
createZipFile:password:
Create zip file with password
- (BOOL)createZipFile:(NSString *)zipFile password:(NSString *)password
Parameters
- zipFile
Path of file to create
- password
The password to use when creating the zip file.
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h
unzipCloseFile
Close the zip file being unzipped
- (BOOL)unzipCloseFile
Return Value
Returns YES
if successful. No if failure.
Declared In
ZipArchive.h
unzipFileTo:overwrite:
Unzip zip file to particular path
- (BOOL)unzipFileTo:(NSString *)path overwrite:(BOOL)overwrite
Parameters
- path
Path of directory to where the files will be unzipped.
- overwrite
BOOL
value indicating whether the files at the path should be overwritten if already found.
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h
unzipOpenFile:
Open zip file to unzip
- (BOOL)unzipOpenFile:(NSString *)zipFile
Parameters
- zipFile
Path of file to open
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h
unzipOpenFile:password:
Open zip file to unzip with password
- (BOOL)unzipOpenFile:(NSString *)zipFile password:(NSString *)password
Parameters
- zipFile
Path of file to open
- password
The password to use when opening the zip file.
Return Value
Returns YES
if successful. NO
if failure.
Declared In
ZipArchive.h