ZipArchive压缩和解压缩
来源:互联网 发布:盘古网络河北销售处 编辑:程序博客网 时间:2024/04/28 23:55
利用Cocopods 添加第三方类库: ZipArchive
压缩:
1. 根据文件管理器创建压缩对象zip;
NSFileManager *manager = [NSFileManager defaultManager];
ZipArchive *zip = [[ZipArchivealloc]initWithFileManager:manager];
2. 根据zip创建压缩包,并存入指定路径;
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/1.zip"];
BOOL isOK =NO;
isOK = [zip CreateZipFile2:pathPassword:@"123"];//每次都会创建一个新的压缩包并打开文件
NSLog(@"创建%@",isOK?@"成功":@"失败");
3. 往压缩包里添加数据;
NSString *fileDirectPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/images”];//获取数据路径;
NSDirectoryEnumerator *enu = [managerenumeratorAtPath:fileDirectPath];//文件管理器遍历该路径的数据,并返回数据集合;
for (NSString *strin enu.allObjects) {//遍历enu,得到每个数据的存储路径;
NSString *imgPath = [fileDirectPathstringByAppendingPathComponent:str];//拼接路径,并添加到压缩包zip;
isOK = [zip addFileToZip:imgPathnewname:str];
NSLog(@"添加%@",isOK?@"成功":@"失败");
}
4.添加完数据,关闭压缩包
isOK = [zip CloseZipFile2];
NSLog(@"关闭%@",isOK?@"成功":@"失败");
解压缩:
1.根据路径和密码打开压缩文件
isOK = [zip UnzipOpenFile:pathPassword:@"123"];
NSLog(@"打开%@",isOK?@"成功":@"失败");
2.获取解压缩的进度以及文件个数
NSString *newPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/1"];
zip.progressBlock = ^(int percentage,int filesProcessed, unsignedlong numFiles){
NSLog(@"%@--%@--%@",@(percentage),@(filesProcessed),@(numFiles));
};
3.解压缩文件
isOK = [zip UnzipFileTo:newPathoverWrite:YES];
NSLog(@"解压缩%@",isOK?@"成功":@"失败");
4.关闭压缩文件
[zip UnzipCloseFile];
- ZipArchive压缩和解压缩
- ZipArchive压缩和解压缩文件
- iOS中使用ZipArchive 压缩和解压缩文件
- 在iOS使用ZipArchive压缩和解压缩文件
- iOS中使用ZipArchive压缩和解压缩文件
- iOS中压缩和解压缩文件--ZipArchive
- iOS中使用ZipArchive 压缩和解压缩文件
- iOS中使用ZipArchive压缩和解压缩文件
- iOS中使用ZipArchive压缩和解压缩文件
- 压缩和解压缩
- 压缩和解压缩
- 压缩和解压缩
- 压缩和解压缩类
- linux压缩和解压缩
- 关于压缩和解压缩
- Linux 压缩和解压缩
- 压缩和解压缩
- java 压缩和解压缩
- 例题5-5 UVA 12096 The SetStack Computer集合栈计算机
- OC 8 属性 内存管理组 对象控制组 重命名组 KVC键值编码
- SSDB:高性能数据库服务器
- MyEclipse安装及安装报错及卸载干净的解决方法
- HBase应用开发回顾与总结系列之二:RowKey行键设计规范
- ZipArchive压缩和解压缩
- vmlinuz
- Windows下如何查看网络IP与端口
- Python collections.defaultdict 笔记
- 用js实现同一页面多个不同运动效果
- IOS-自定义View 覆盖到Tabbar上, View不响应事件问题
- OC 9 内存管理方式 引用计数机制 内存管理的基本原则 copy的实现
- 6 ZigZag Conversion
- Hbase客户端