ZipArchive和SSZipArchive使用详解
一、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使用详解的更多相关文章
- SSZipArchive使用详解
下载SSZipArchive,点击我.或者自己在这里下载. SSZipArchive功能: 解压zip文件 解压密码保护的zip文件 创建zip文件 追加到zip文件 压缩文件 使用一个名字来压缩NS ...
- SSZipArchive的使用详解和遇到的问题
https://blog.csdn.net/zhengang007/article/details/51019479 2016年03月30日 版权声明:本文为博主原创文章,转载请注明作者和原文链接. ...
- Podfile文件用法详解
https://www.jianshu.com/p/b8b889610b7e 2018.01.09 15:51* 字数 2343 阅读 6263评论 3喜欢 34 前言 iOS开发会经常用到cocoa ...
- Linq之旅:Linq入门详解(Linq to Objects)
示例代码下载:Linq之旅:Linq入门详解(Linq to Objects) 本博文详细介绍 .NET 3.5 中引入的重要功能:Language Integrated Query(LINQ,语言集 ...
- 架构设计:远程调用服务架构设计及zookeeper技术详解(下篇)
一.下篇开头的废话 终于开写下篇了,这也是我写远程调用框架的第三篇文章,前两篇都被博客园作为[编辑推荐]的文章,很兴奋哦,嘿嘿~~~~,本人是个很臭美的人,一定得要截图为证: 今天是2014年的第一天 ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- Java 字符串格式化详解
Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...
- Android Notification 详解(一)——基本操作
Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
随机推荐
- redis php扩展安装下载
php的redis 扩展下载地址 Windows :http://windows.php.net/downloads/pecl/releases/redis/2.2.7/ 下载对应版本,一般有两个 n ...
- 如何获取客户端MAC地址(三个方法)
方法一: 调用Windows的DOS命令,从输出结果中读取MAC地址: public static String getMACAddress() { String address = "&q ...
- jQuery 2.0发布,不再支持IE6/7/8
有时发现jQuery库引用的都对,javascript代码写的也没问题,可是jquery就是出现问题,额--我发现换个jquery库就没问题了,长时间不关注jquery的问题而已: 很多人都没有使用最 ...
- .NET之委托
有些.NET中的高级特性,比如:委托! 有一种怎么也搞不懂的赶脚... 博客读了好几篇,代码也动手写了,书中的一些介绍也看了, 各种搜索关于委托的,至今还处于"会用"的阶段. 该怎 ...
- 2015baidu复赛 矩形面积(包凸 && ps:附quickhull模板)
矩形面积 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Linux下安装和配置JDK与Tomcat(入门版)
JDK路径:/usr/java/jdk1.6.0_25 Tomcat路径:/usr/local/apache-tomcat 1. 下载jdk6.0(选择“.rpm.bin”结尾的,6u25版本) ht ...
- HTTPS科普扫盲帖 对称加密 非对称加密
http://www.cnblogs.com/chyingp/p/https-introduction.html
- Java Io 之拷贝文件性能比较
前面我们共讨论了拷贝文件有三种方式: 1. 第一种,一个字节一个字节的进行拷贝文件操作. 2. 第二种,使用字节数据批量的进行拷贝文件操作. 3. 第三种,使用带缓冲输入输出流来拷贝文件. 那么哪一种 ...
- [POJ1765]November Rain
[POJ1765]November Rain 试题描述 Contemporary buildings can have very complicated roofs. If we take a ver ...
- 剑指Offer 用两个栈实现队列
题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路: 入队:将元素进栈A 出队:判断栈B是否为空,如果为空,则将栈A中所有元素pop,并push进 ...