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 ...
随机推荐
- webpack 前端构建
一.建立简单的项目目录 1.创建 manager 根目录(作为项目根目录)2.执行 npm init,在根目录manager下自动生成 package.json文件3.npm install webp ...
- FireBug调试工具笔记
Firebug是网页浏览器 Mozilla Firefox下的一款开发类插件, 现属于Firefox的五星级强力推荐插件之一.它集HTML查看和编辑.Javascript控制台.网络状况监视 ...
- 基于zepto判断mobile的横竖屏状态
借用jquery mobile中的代码,删除了一些多余的部分,简单的基于zepto的模块 var CheckOrientation = (function(){ var win = $( window ...
- VPN添加静态路由表(指定程序或资源走VPN)
在某此情况下,我们希望为VPN客户端指定线路,比如只有公司的资源或网站才使用VPN连接,其它的网络请求依然走他们自己的默认网关. 这种情况下,我们就需要给VPN客户端添加静态路由规则并取消VPN连接的 ...
- POJ 2115 C Looooops
扩展GCD...一定要(1L<<k),不然k=31是会出错的 .... C Looooops Time Limit: 1000MS Mem ...
- 微信电脑版微信1.1 for Windows更新 可@人/转发撤回消息/可播小视频
微信电脑版微信1.1 for Windows发布更新了,版本号为1.1.0.18,群聊可@人/可转发撤回消息/可播小视频,功能越来越接近微信手机版了. 本次更新的一些新特点: 群聊中可以@人. 消息可 ...
- cf.301.D. Bad Luck Island(dp + probabilities)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- mytbatis小问题
使用mybatis出现以下异常 SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, Postgr ...
- LVS NAT模式
LVS-NAT 三台虚拟机都是centos 6.5 关闭防火墙和selinux 角色 IP地址 备注 LVS负载调度器 eth0:192.168.119.128(内网) eth1:192.168.94 ...
- 【转】将datatable数据转化成list
#region 将datatable数据转化成list public static List<T> ToList<T>(this DataTable dt) where T ...