一、SSZipArchive

1.简介

SSZipArchive是iOS和Mac上一个简单实用的压缩和解压插件。用途包括:
1.解压zip文件;
2.解压密码保护的ZIP文件;
3.创建新的zip文件;
4.追加文件到现有的压缩;
5.压缩文件;
6.压缩NSData(带有文件名)

SSZipArchive的GitHub地址:https://github.com/ZipArchive/ZipArchive

2.压缩方法

压缩指定文件代码:

 /**
* SSZipArchive压缩
*/
-(void)ssZipArchiveWithFiles
{
//Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
  //zip压缩包保存路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"SSZipArchive.zip"];
//需要压缩的文件
NSArray *filesPath = @[
@"/Users/apple/Desktop/demo/LaunchImage-2-700-568h@2x.png",
@"/Users/apple/Desktop/demo/LaunchImage-2-700@2x.png",
@"/Users/apple/Desktop/demo/LaunchImage-2-800-667h@2x.png",
@"/Users/apple/Desktop/demo/LaunchImage-2-800-Landscape-736h@3x.png"
];
//创建不带密码zip压缩包
BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withFilesAtPaths:filesPath];
//创建带密码zip压缩包
//BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withFilesAtPaths:filesPath withPassword:@"SSZipArchive.zip"];
}

压缩指定文件夹代码:

 /**
* SSZipArchive压缩
*/
-(void)ssZipArchiveWithFolder
{
//Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
  //zip压缩包保存路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"SSZipArchive.zip"];
//需要压缩的文件夹路径
NSString *folderPath = @"/Users/apple/Desktop/demo/";
//创建不带密码zip压缩包
BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:folderPath ];
//创建带密码zip压缩包
//BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:folderPath withPassword:@"SSZipArchive.zip"];
}

3.解压方法

代码:

 /**
* SSZipArchive解压
*/
-(void)uSSZipArchive
{
//Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
//解压目标路径
NSString *destinationPath =[cachesPath stringByAppendingPathComponent:@"SSZipArchive"];
//zip压缩包的路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"SSZipArchive.zip"];
//解压
BOOL isSuccess = [SSZipArchive unzipFileAtPath:path toDestination:destinationPath];
}

二、ZipArchive

1.简介

ZipArchive可以解压和压缩

2.压缩方法

代码:

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

3.解压方法

代码:

 /**
* ZipArchive解压
*/
-(void)uZipArchive
{
//创建解压缩对象
ZipArchive *zip = [[ZipArchive alloc]init];
//Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
  //解压目标路径
NSString *savePath =[cachesPath stringByAppendingPathComponent:@"ZipArchive"];
  //zip压缩包的路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"ZipArchive.zip"];
//解压不带密码压缩包
[zip UnzipOpenFile:path];
//解压带密码压缩包
//[zip UnzipOpenFile:path Password:@"ZipArchive.zip"];
//解压
[zip UnzipFileTo:savePath overWrite:YES];
//关闭解压
BOOL success = [zip UnzipCloseFile];
}

ZipArchive和SSZipArchive使用详解的更多相关文章

  1. SSZipArchive使用详解

    下载SSZipArchive,点击我.或者自己在这里下载. SSZipArchive功能: 解压zip文件 解压密码保护的zip文件 创建zip文件 追加到zip文件 压缩文件 使用一个名字来压缩NS ...

  2. SSZipArchive的使用详解和遇到的问题

    https://blog.csdn.net/zhengang007/article/details/51019479 2016年03月30日 版权声明:本文为博主原创文章,转载请注明作者和原文链接. ...

  3. Podfile文件用法详解

    https://www.jianshu.com/p/b8b889610b7e 2018.01.09 15:51* 字数 2343 阅读 6263评论 3喜欢 34 前言 iOS开发会经常用到cocoa ...

  4. Linq之旅:Linq入门详解(Linq to Objects)

    示例代码下载:Linq之旅:Linq入门详解(Linq to Objects) 本博文详细介绍 .NET 3.5 中引入的重要功能:Language Integrated Query(LINQ,语言集 ...

  5. 架构设计:远程调用服务架构设计及zookeeper技术详解(下篇)

    一.下篇开头的废话 终于开写下篇了,这也是我写远程调用框架的第三篇文章,前两篇都被博客园作为[编辑推荐]的文章,很兴奋哦,嘿嘿~~~~,本人是个很臭美的人,一定得要截图为证: 今天是2014年的第一天 ...

  6. EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解

    前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...

  7. Java 字符串格式化详解

    Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...

  8. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  9. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

随机推荐

  1. R获取股票数据

    R中好几个Pkg都提供了股票数据的在线下载方法,如果非得在其中找出一个最好的,那么quantmod当之无愧!举一个例子,譬如下载沪市大盘数据,代码可以是: library(quantmod)SSE & ...

  2. [PHP知识点乱炖]四、全局变量——小偷从良记

    本章要讲的是PHP的全局变量. 这里讲个小故事: 很多年前,一个很聪明的小偷,想去偷一户人家的钱.可是他偷不到主人的钥匙,怎么办呢? 他想到了一个办法,去之前嚼了一块口香糖,口香糖的牌子是“大大泡泡糖 ...

  3. iOS设置分割线从边框顶端开始

    好方法,本来是在xib里面设置自定义分割线位置,结果还是差15像素,该方法亲测好使. IOS8 设置TableView Separatorinset 分割线从边框顶端开始 (转) 在ios8上 [Ta ...

  4. IEnumerable<> ICollection <> IList<> 区别

    IEnumerable< ICollection < IList区别 public interface IEnumerable { IEnumerator GetEnumerator(); ...

  5. Back to Edit Distance(LCS + LIS)

    Given 2 permutations of integers from 1 to N, you need to find the minimum number of operations nece ...

  6. Linux C select函数详解

    select IO复用机制: http://www.cnblogs.com/hjslovewcl/archive/2011/03/16/2314330.html http://blog.csdn.ne ...

  7. node.js安装cnpm 提高下载速度

    由于中国网络特殊的网络环境原因,国外部分网站访问速度很慢. 安装node.js时,使用npm 安装软件速度也很慢,可以使用阿里的cnpm来解决 官方网址:http://npm.taobao.org: ...

  8. 写给喜欢用Block的朋友(ios Block)

    作者:fengsh998原文地址:http://blog.csdn.net/fengsh998/article/details/38090205转载请注明出处如果觉得文章对你有所帮助,请通过留言或关注 ...

  9. Swift初学有一点难理解的东西,整理了一下,想明白了。

      func makeIncrementer() -> (Int -> Int) {      func addOne(number: Int) -> Int {           ...

  10. Android6.0以后动态增加权限

    private void test() throws IOException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { in ...