iPhone zip压缩与解压
转载自: http://linglong117.blog.163.com/blog/static/2771454720107105820275/http://www.devdiv.net/viewthread-19937(链接)ziparchive是基于开源代码"MiniZip"的zip压缩与解压的Objective-C 的Class,使用起来非常的简单.你只需要把代码加进你的工程,然
转载自: http://linglong117.blog.163.com/blog/static/2771454720107105820275/
http://www.devdiv.net/viewthread-19937(链接)
ziparchive是基于开源代码"MiniZip"的zip压缩与解压的Objective-C 的Class,使用起来非常的简单.你只需要把代码加进你的工程,然后把zlib库添加到工程就可以了.
添加zlib 库
直接#improt “zlib.h”
再导入libz.1.2.3.dylib
ziparchive可以在googlecode上下载,地址如下:http://code.google.com/p/ziparchive/
参考贴:http://www.iphonedevsdk.com/foru ... p-format-files.html
http://www.iphonedevsdk.com/forum/iphone-sdk-development/7615-simple-objective-c-class-zip-unzip-zip-format-files.html
压缩:
ZipArchive可以压缩多个文件,只需要把文件一一addFileToZip即可.
CODE:
ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
NSString* image1 = [dcoumentpath stringByAppendingString:@"/image1.jpg"] ;
NSString* image2 = [dcoumentpath stringByAppendingString:@"/image2.jpg"] ;
BOOL ret = [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
if( ![zip CloseZipFile2] )
{
l_zipfile = @"";
}
[zip release];
解压缩:
CODE:
ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;
if( [zip UnzipOpenFile:l_zipfile] )
{
BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
if( NO==ret )
{
}
[zip UnzipCloseFile];
}
[zip release];
但是stringByAppendingPathComponent应该是不需要"/"了。
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)