Categories
Recent Posts

Posts Tagged ‘unzip’

ZipArchive has been updated to version 1.1 (更新至1.1版)

ZipArchive is a wrapper class to compress and uncompress zip files for Objective-C and cocoa use. It’s developed based on minizip and zlib.  The latest version is 1.1, new feature includes :

✩ create password protected zip files

✩ unzip password protected zip files

To obtain the new version up to date, please visit the project website http://code.google.com/p/ziparchive/

ZipArchive 是基于minizip和zlib的Objective-C 类, 用于创建和解压zip格式的压缩文件, 最新版本为1.1, 新增功能如下:

✩ 创建有密码保护的zip文件

✩ 解压有密码保护的zip文件

为了保证获取最新的版本, 请访问该项目网页 http://code.google.com/p/ziparchive/

Objective-C class for zip/unzip zip format files

This is a simple class for compressing and extracting files. It works depend on minizip, which is a open source zip format library. And it’s included in the attachment.

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.

The code below shows you how to use it.

To create and add files to a zip

1
2
3
4
5
6
7
		BOOL ret = [zip CreateZipFile2:l_zipfile];
		ret = [zip addFileToZip:l_photo newname:@"photo.jpg"];
		if( ![zip CloseZipFile2] )
		{
			l_zipfile = @"";
		}
		[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.

1
2
3
4
5
6
7
8
9
10
11
	ZipArchive* za = [[ZipArchive alloc] init];
	if( [za UnzipOpenFile:@"/Volumes/data/testfolder/Archive.zip"] )
	{
		BOOL ret = [za UnzipFileTo:@"/Volumes/data/testfolder/extract" overWrite:YES];
		if( NO==ret )
		{
		}
		[za UnzipCloseFile];
	}
 
	[za release];

zip/unzip wrapper class for Objective-C