文件压缩与解压缩

第三方解压缩框架——SSZipArchive
注意:需要引入libz.dylib框架 // 是个动态链接库
//解压 Unzipping
NSString *zipPath = @"path_to_your_zip_file";// 要解压文件地址
NSString *destinationPath=@"path_to_the_folder_where_you_want_it_unzipped";// 解压后文件要保存的地址
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];

//压缩 Zipping
NSString *zippedPath = @"path_where_you_want_the_file_created";// 压缩后文件的保存地址
NSArray *inputPaths = [NSArray arrayWithObjects:// 要压缩文件的地址,是个数组
                       [[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpg"],
                       [[NSBundle mainBundle] pathForResource:@"photo2" ofType:@"jpg"]
                       nil];
[SSZipArchive createZipFileAtPath:zippedPath withFilesAtPaths:inputPaths];

 1 - (void)createZip
 2 {
 5     // 1.获得mainBundle中所有的png的图片路径
 6     NSArray *pngs = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
 7     
 8     // 2.zip文件路径
 9     NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
10     NSString *zipFilepath = [caches stringByAppendingPathComponent:@"pngs.zip"];
11     
12     // 3.创建zip文件
13     [SSZipArchive createZipFileAtPath:zipFilepath withFilesAtPaths:pngs];
14 }

 

posted @ 2014-06-29 18:07  delegate  阅读(158)  评论(0)    收藏  举报