【转】iOS开发之压缩与解压文件
ziparchive是基于开源代码”MiniZip”的zip压缩与解压的Objective-C 的Class,使用起来非常的简单
方法:从http://code.google.com/p/ziparchive/ 上下载ZipArchive.zip,解压后将代码加入工程中,并且把zlib库添加到工程中
使用方法:
1. 压缩:ZipArchive可以压缩多个文件,只需要把文件一一addFileToZip即可.

ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ; NSString* image1 = [documentpath stringByAppendingString:@"/image1.jpg"] ;
NSString* image2 = [documentpath stringByAppendingString:@"/image2.jpg"] ; BOOL ret = [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
if( ![zip CloseZipFile2] )
{
l_zipfile = @"";
}
[zip release];

2. 解压缩:

ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ;
NSString* unzipto = [documentpath stringByAppendingString:@"/test"] ;
if( [zip UnzipOpenFile:l_zipfile] )
{
BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
if( NO==ret )
{
}
[zip UnzipCloseFile];
}
[zip release];

from:http://www.cnblogs.com/foxmin/archive/2012/09/18/2690359.html
【转】iOS开发之压缩与解压文件的更多相关文章
- iOS开发之压缩与解压文件
ziparchive是基于开源代码”MiniZip”的zip压缩与解压的Objective-C 的Class,使用起来非常的简单 方法:从http://code.google.com/p/ziparc ...
- AIX系统上压缩与解压文件
压缩. 命令格式: #tar -cvf (或xvf)+文件名+设备 C:是本地到其他设备 x:是其他设备到本地 r:是追加,比如打包时,将其他文件追加进来使用该参数. t:显示tar包里的内容,但还原 ...
- Linux学习笔记之AIX系统上压缩与解压文件
0x00 概述 AIX机器真难用,一时半会还真适应不了. 0x01 压缩tar 命令格式: # tar -cvf (或xvf)+文件名+设备 C:是本地到其他设备 x:是其他设备到本地 r:是追加 ...
- C# 压缩、解压文件夹或文件(带密码)
今天梳理一下项目中用到的压缩.解压文件夹或文件的方法,发现因为需求不同,已经用了好几个不同组件.今天就好好整理记录下,别下次遇到需求又重头开始了. DotNetZip DotNetZip是一个开源的免 ...
- Linux命令(16)压缩,解压文件
tar: 简介:tar命令只是把目录打包成一个归档(文件),并不负责压缩.在tar命令中可以带参数调用gzip或bzip2压缩.因为gzip和bzip2只能压缩单个文件. 在linux下是不需要后缀名 ...
- C#工具类:使用SharpZipLib进行压缩、解压文件
SharpZipLib是一个开源的C#压缩解压库,应用非常广泛.就像用ADO.NET操作数据库要打开连接.执行命令.关闭连接等多个步骤一样,用SharpZipLib进行压缩和解压也需要多个步骤.Sha ...
- 本地上传文件至服务器的技巧(linux文件压缩及解压文件)
linux(ubuntu)文件解压及压缩文件 ubuntu支持文件的解压及压缩功能, 如果ubuntu上面没有安装过unzip工具的话,可以通过下面命令安装: sudo apt-get install ...
- 使用SharpZipLib压缩与解压文件
using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections.Generic; using System.IO; ...
- (转)使用 linux tar 命令压缩与解压文件
原文链接 http://www.cnblogs.com/qq78292959/archive/2011/07/06/2099427.html tar -c: 建立压缩档案-x:解压-t:查看内容-r: ...
随机推荐
- 七层登录——VB.NET版
敲完三层后,感觉还是对三层架构没有那么亲切,和小伙伴交流后,他们说多多敲几遍,就懂了,其实就是那么几条线,所以:不管会不会,先去做吧! 下面是关于七层的包图: 我的解决方案: 代码部分: U层: &l ...
- Windows 在目录中搜索哪个文件中有指定字符串
findstr /s /i "string" *.* 表示,当前目录以及子目录下的所有文件中查找"string"这个字符串. *.*表示所有类型的文件. /s ...
- Age of Moyu (2018 Multi-University Training Contest 7)
题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ ,f= ...
- 总结工作中用到的ES6语法,方便工作中查看,也总结一下经验
1.模板字符串: 表现形式:${} 举例子: import axios from 'axios'; let base = 'https://www.baidu.com/home/msg/data/pe ...
- Scala_Load csv data to hive via spark2.1_via pass parameters
prepare csv: # vim /tmp/cars.csv year,make,model,comment,blank ","Tesla","S" ...
- CodeForces - 589A
题目链接:http://codeforces.com/problemset/problem/589/A Polycarp has quite recently learned about email ...
- UVA 5986 - Wizarding Duel 超级脑洞题
给出n个人,每个人两两比赛一场,一共有C(n,2)场比赛,现在给出一个榜,问其是否合法.不合法的话,就改成合法,输出最小需要改的变化. 分数一定是C(n,2)的了, 不和法的情况,比如0,0,2,是不 ...
- POJ 1556 E - The Doors
题意:给定n堵墙,现在要你从(0,5)走去(10,5)的最短距离 思路:刚开始还想模拟,就是从(0,5)走,每次x向右一格,然后判断有没和线段相交就可以.但是它的们有可能是小数形式给出的,这样就GG了 ...
- C# 读写XML文件的方法
C# 读写XML文件的方法 一.写XML文件 XmlDocument xmlDocument = new XmlDocument();xmlDocument.AppendChild(xmlDocume ...
- Hibernate的工作流程以及三种状态(面试题)
Hibernate的工作流程以及三种状态 部分转载自:http://www.cnblogs.com/fifiyong/p/6390699.html Hibernate的工作流程: 1. 读取并解析配置 ...