文件压缩解压缩

参考资料

使用方法

1. 创建项目,下载SSZipArchive.zip,将SSZipArchive文件夹导入到项目中

752372-20161019194439232-1230713654.png

2. 导入三方需要的libz.tbd,否则会报错

752372-20161019194604138-34964487.png

导入头文件 #import “SSZipArchive.h” 即可进行相关操作
#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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值