#import "ViewController.h"
#import "SSZipArchive.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark 压缩点击事件
- (IBAction)compressionClick:(UIButton *)sender {
/** 压缩文件夹
zipFile :产生的zip文件的最终路径
directory : 需要进行的压缩的文件夹路径
*/
NSString *zipFile = @"/Users/macbook/Desktop/压缩测试/zip压缩文件.zip";
NSString *directory = @"/Users/macbook/Desktop/压缩测试/zip压缩文件";
[SSZipArchive createZipFileAtPath:zipFile withContentsOfDirectory:directory];
/** 文件的压缩
zipFile :产生的zip文件的最终路径
files : 这是一个数组,数组里面存放的是需要压缩的文件的路径
files = @[@”/Users/apple/Destop/1.png”, @”/Users/apple/Destop/3.txt”]
*/
NSString *zipFileOne = @"/Users/macbook/Desktop/压缩测试/img.zip";
NSArray *files = @[@"/Users/macbook/Desktop/压缩测试/zip压缩文件/Snip20161019_9.png",@"/Users/macbook/Desktop/压缩测试/zip压缩文件/Snip20161019_10.png"];
[SSZipArchive createZipFileAtPath:zipFileOne withFilesAtPaths:files];
}
#pragma mark 解压缩
- (IBAction)decompressionClick:(UIButton *)sender {
NSURL *url = [NSURL URLWithString:@"http://www.gonghuizhudi.com/file/images.zip"];
NSURLSessionDownloadTask *task = [[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
/** 解压缩
location.path : 貌似是申请下来的数据的路径
caches :解压缩后的存储路径
*/
NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@"caches ======= %@",caches);
NSLog(@"location.path ====== %@",location.path);
[SSZipArchive unzipFileAtPath:location.path toDestination:caches];
}];
[task resume];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end