• 使用SSZipArchive第三方库解压zip包


    //
    //  ViewController.m
    //  解压缩zip包开发
    //
    //  Created by 张凯泽 on 16/3/9.
    //  Copyright © 2016年 rytong_zkz. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "SSZipArchive.h"
    @interface ViewController ()
    - (IBAction)PressZipClick:(id)sender;
    - (IBAction)UnarchiveZipClick:(id)sender;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
    }
    
    //压缩zip包
    - (IBAction)PressZipClick:(id)sender {
        NSArray *pngs = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
        
        // zip文件路径
        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        NSString *zipFilepath = [caches stringByAppendingPathComponent:@"pngs.zip"];
        NSLog(@"zipFilepath = %@",zipFilepath);
        
        // 创建zip文件
        //[SSZipArchive createZipFileAtPath:zipFilepath withFilesAtPaths:pngs];
        [SSZipArchive createZipFileAtPath:zipFilepath withFilesAtPaths:pngs withPassword:@"zkz"];
    }
     //解zip包
    - (IBAction)UnarchiveZipClick:(id)sender {
        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        NSString *filepath = [caches stringByAppendingPathComponent:@"pngs.zip"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 解压(文件大, 会比较耗时,所以放到子线程中解压)
            //[SSZipArchive unzipFileAtPath:filepath toDestination:caches];
            NSError * error;
            [SSZipArchive unzipFileAtPath:filepath toDestination:caches overwrite:YES password:@"zkz" error:&error];
            NSLog(@"error = %@",error);
            NSLog(@"解压完成");
        });
    }
    @end
  • 相关阅读:
    MVC4 中Remote的使用
    NHibernate遇到的问题集 持续更新。
    2014总结,2015展望
    Redis结合EntityFramework结合使用的操作类
    Entity Framwork db First 中 Model验证解决办法。
    「面经」阿里蚂蚁金服 offer 之路
    最长公共子序列-LCS
    阿里面试题解答-倒排索引
    如何解决ubuntu下Chromium 新建的应用快捷方式图标模糊的问题
    join sleep yield
  • 原文地址:https://www.cnblogs.com/zkzzkz/p/5258365.html
Copyright © 2020-2023  润新知