zoukankan      html  css  js  c++  java
  • 压缩和解压缩(I)

    ZipArchive

    压缩方法

     1 -(void)zipArchiveWithFiles
     2     {
     3          //创建解压缩对象
     4          ZipArchive *zip = [[ZipArchive alloc]init];
     5          //Caches路径
     6          NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
     7          //zip压缩包保存路径
     8          NSString *path = [cachesPath stringByAppendingPathComponent:@"ZipArchive.zip"];//创建不带密码zip压缩包
     9          //创建zip压缩包
    10          [zip CreateZipFile2:path];
    11          //创建带密码zip压缩包
    12          //[zip CreateZipFile2:path Password:@"ZipArchive.zip"];
    13         //添加到zip压缩包的文件
    14          [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-700-568h@2x.png" newname:@"1.png"];
    15          [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-700@2x.png" newname:@"2.png"];
    16          [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-800-667h@2x.png" newname:@"3.png"];
    17          [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-800-Landscape-736h@3x.png" newname:@"4.png"];
    18          //关闭压缩
    19          BOOL success = [zip CloseZipFile2];
    20      }
    View Code

    解压缩方法

     1 -(void)uZipArchive
     2     {
     3          //创建解压缩对象
     4          ZipArchive *zip = [[ZipArchive alloc]init];
     5          //Caches路径
     6          NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
     7        //解压目标路径
     8          NSString *savePath =[cachesPath stringByAppendingPathComponent:@"ZipArchive"];
     9        //zip压缩包的路径
    10          NSString *path = [cachesPath stringByAppendingPathComponent:@"ZipArchive.zip"];
    11          //解压不带密码压缩包
    12          [zip UnzipOpenFile:path];
    13          //解压带密码压缩包
    14          //[zip UnzipOpenFile:path Password:@"ZipArchive.zip"];
    15          //解压
    16          [zip UnzipFileTo:savePath overWrite:YES];
    17          //关闭解压
    18          BOOL success = [zip UnzipCloseFile];
    19      }
    View Code
  • 相关阅读:
    关于软件工程是不是教那些不会写程序的人开发软件的一些看法。
    学习这门课的一些问题
    软件测试的平台
    课程上不明白的问题
    目前流行的源程序版本管理软件和项目管理软件都有哪些, 各有什么优缺点?
    自我介绍
    【软件工程】提问回顾与个人总结
    Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解
    elasticsearch-py 解决 too_long_frame_exception 问题
    Redis集群学习笔记
  • 原文地址:https://www.cnblogs.com/EchoHG/p/9064967.html
Copyright © 2011-2022 走看看