文件的压缩和解压缩
此操作需要借助一个第三方框架:SSZipArchive
要实现的方法也很简单:
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self unzip];
}
-(void)zip
{
NSArray *paths = @[@"/Users/wujian/Desktop/Snip20160716_129.png",@"/Users/wujian/Desktop/Snip20160716_130.png"];
/*
第一个参数:打包后文件存储位置
第二个参数:要压缩的所有文件的文件路径
*/
[SSZipArchive createZipFileAtPath:@"/Users/wujian/Desktop/img.zip" withFilesAtPaths:paths];
}
-(void)zip2
{
[SSZipArchive createZipFileAtPath:@"/Users/wujian/Desktop/xxxx.zip" withContentsOfDirectory:@"/Users/wujian/Desktop/img"];
}
-(void)unzip
{
/*
第一个参数:要解压的文件路径
第二个参数:解压后存储的路径
*/
[SSZipArchive unzipFileAtPath:@"/Users/wujian/Desktop/xxxx.zip" toDestination:@"/Users/wujian/Desktop/oooo"];
}
@end