IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    文件的压缩和解压 - w听话

    w听话发表于 2015-10-13 13:50:00
    love 0

    文件的压缩和解压

    • 使用第三方框架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听话
    • 原创文章,版权声明:自由转载-哈哈哒~ | windy

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


    本文链接:文件的压缩和解压,转载请注明。



沪ICP备19023445号-2号
友情链接