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]; |
转载自:FLYBLOG [http://www.flyblog.info]
本文链接地址:http://www.flyblog.info/catprogramming/202.html
相关文章
Objective-C class for zip/unzip zip format files…
You’ve been kicked (a good thing) – Trackback from iPhoneKicks.com – iPhone SDK links, community driven…
Hi,
I new to IPhone SDK Programming.can you please guide me how i can use this classes inside Xcode project.
I tried your code to unzip files, it works on simulator, but when I tried on Device, I got following linked error, any idea?
“_deflate”, referenced from:
_zipWriteInFileInZip in zip.o
_zipCloseFileInZipRaw in zip.o
“_deflateEnd”, referenced from:
_zipCloseFileInZipRaw in zip.o
“_crc32″, referenced from:
_zipWriteInFileInZip in zip.o
_unzReadCurrentFile in unzip.o
_unzReadCurrentFile in unzip.o
“_inflateEnd”, referenced from:
_unzCloseCurrentFile in unzip.o
“_get_crc_table”, referenced from:
_zipOpenNewFileInZip3 in zip.o
_unzOpenCurrentFile3 in unzip.o
“_inflate”, referenced from:
_unzReadCurrentFile in unzip.o
“_deflateInit2_”, referenced from:
_zipOpenNewFileInZip3 in zip.o
“_inflateInit2_”, referenced from:
_unzOpenCurrentFile3 in unzip.o
ld: symbol(s) not found
Thank you very much!
Hi,
I tried to use this source in my application and got the same the same result.
Are there any installation instructions anywhere ???
Thanks
I found that adding the zlibz.dylib framework in xcode fixed the missing symbol errors.
iam new to iphone development please please help me in this , how i can use the above classes in my xcode project , iam getting so many errors.
Hi,
I am using your library for Creating New Zip file and Unzipping from the ZIP file.
I have typical problem, i will get the ZIP file stream in NSData. Can you help me to read the NSData directly (This dosen’t has any header info) instead of File.
OR
How to Store the NSData in a proper ZIP format.
Please help me.
Regards,
Anil.
Can any one please help me with some explanation .. I need to implement this asap. Plssssssssssss