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 ...
随机推荐
- web 开发前端学习
调试插件:http://www.getpostman.com/ http://bootstrap.evget.com/javascript.html bootstrap: http://www.bo ...
- QT点击"X"按钮,调用closeEvent()函数来实现调用特定事件(附:粗略介绍QT的信号与槽的使用方法)
背景: QT在用户关闭窗口(直接点击"X"键)时,程序一般都需要做一些善后的事情,就我现在的程序来说,既关闭USB.如何实现? 正文: 首先,在对应窗体的".h" ...
- redis-key2
package com.ztest.redis; import java.util.List; import redis.clients.jedis.Jedis; import com.sun.ist ...
- Sql统计一个字符串在另一个字符串出现的次数的函数-fnQueryCharCountFromString
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ),)) returns int as begin declare @pos int,@n int , ...
- FineUI第十七天---- 表格之扩展列
{ sb.AppendFormat(]); 1.通过表格的SelectedRowIndexArray获得选中行的索引号列表: 2.通过表格的DataKeys(二维数组)获取本行的数据 ...
- jQuery中$(function(){})与(function($){})(jQuery)的区别
首先,这两个函数都是在页面载入后执行的函数,其中两者的区别在于: 在jQuery中$(function(){})等同于jQuery(function(){}),另一个写法为jQuery(documen ...
- mysql 在linux 修改账号密码
1.root用户登录到mysql数据库代码示例:/usr/local/mysql/bin/mysql -u root -p (输入密码进入mysql)2.进入mysql,输入:代码示例:use mys ...
- junk
var mydate1 = new Date($('.stt').html()); var mydate2 = new Date($('.ett').html()); if (window.Activ ...
- Android应用性能优化
整理自http://androidperformance.com的几篇博客 代码内存优化-Java篇 避免创建不必须的对象,虽然GC可以回收不用的对象,但为对象分配内存和回收它们同样是需要消耗资源的. ...
- mac 下载安装 IntelliJ IDEA Tomcat
(1)Download IntelliJ IDEA https://www.jetbrains.com/idea/download/ (2)找了个激活码 http://www.oschina.net/ ...