文件的压缩和解压

文件的压缩和解压

  • 使用第三方框架ZipArchive

  • 下载地址:
    https://github.com/ZipArchive/ZipArchive
  • 注意:
    • 1.需要引入libz.dylib框架
    • 2.导入头文件Main.h

  • 如何引入libz.dylib框架 ?

引入libz.dylib框架


核心代码

  • 创建压缩文件
 //  压缩方式1 
+ (BOOL)createZipFileAtPath:(NSString *)path
           withFilesAtPaths:(NSArray *)paths;
 // 压缩方式2
+ (BOOL)createZipFileAtPath:(NSString *)path
    withContentsOfDirectory:(NSString *)directoryPath;

 // 解压
+ (BOOL)unzipFileAtPath:(NSString *)path
          toDestination:(NSString *)destination
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    // 压缩1
//    [self zip1];

    // 压缩2
//    [self zip2];

    // 解压
    [self unZip];

}

压缩的方式1

- (void)zip2 {

    NSArray *filesPath = @[
                           @"/Users/hwm/Desktop/zip/Snip20151001_3.png",
                           @"/Users/hwm/Desktop/zip/Snip20151004_9.png",
                           @"/Users/hwm/Desktop/zip/Snip20151004_10.png"
                           ];
    /*
     第一个参数:创建的zip放在哪里
     第二个参数:要压缩哪些文件
     */
    [Main createZipFileAtPath:@"/Users/hwm/Desktop/MM.zip" withFilesAtPaths:filesPath];
}

压缩方式2

- (void)zip1 {

    /*
     第一个参数:创建的zip放在哪里
     第二个参数:要压缩的文件路径
     */
    [Main createZipFileAtPath:@"/Users/hwm/Desktop/hwm.zip" withContentsOfDirectory:@"/Users/hwm/Desktop/zip"];
}

解压

- (void)unZip {

    /*
     第一个参数:需要解压的zip在哪里
     第二个参数:解压的文件放到哪里
     */
    [Main unzipFileAtPath:@"/Users/hwm/Desktop/hwm.zip" toDestination:@"/Users/hwm/Desktop/unZipMM.zip"];
}
  • Posted by 博客园·w听话
  • 联系作者 简书·windy蚊子
  • 原创文章,版权声明:自由转载-哈哈哒~ | windy

  • 呵呵哒?
  • Good good study, day day up

转载于:https://www.cnblogs.com/WMHaa/p/4876004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值