开源项目objective-zip
Objective-Zip is a small Cocoa/Objective-C library that wraps ZLib and MiniZip in an object-oriented friendly way.
项目地址:
http://code.google.com/p/objective-zip/
部分使用代码:(代码来自官网下载)
1 - (void) test { 2 NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; 3 4 @try { 5 NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 6 NSString *filePath= [documentsDir stringByAppendingPathComponent:@"test.zip"]; 7 8 [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening zip file for writing..." waitUntilDone:YES]; 9 10 ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; 11 12 [self performSelectorOnMainThread:@selector(log:) withObject:@"Adding first file..." waitUntilDone:YES]; 13 14 ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest]; 15 16 [self performSelectorOnMainThread:@selector(log:) withObject:@"Writing to first file's stream..." waitUntilDone:YES]; 17 18 NSString *text= @"abc"; 19 [stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]]; 20 21 [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing first file's stream..." waitUntilDone:YES]; 22 23 [stream1 finishedWriting]; 24 25 [self performSelectorOnMainThread:@selector(log:) withObject:@"Adding second file..." waitUntilDone:YES]; 26 27 ZipWriteStream *stream2= [zipFile writeFileInZipWithName:@"x/y/z/xyz.txt" compressionLevel:ZipCompressionLevelNone]; 28 29 [self performSelectorOnMainThread:@selector(log:) withObject:@"Writing to second file's stream..." waitUntilDone:YES]; 30 31 NSString *text2= @"XYZ"; 32 [stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]]; 33 34 [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing second file's stream..." waitUntilDone:YES]; 35 36 [stream2 finishedWriting]; 37 38 [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing zip file..." waitUntilDone:YES]; 39 40 [zipFile close]; 41 [zipFile release]; 42 43 [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening zip file for reading..." waitUntilDone:YES]; 44 45 ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; 46 47 [self performSelectorOnMainThread:@selector(log:) withObject:@"Reading file infos..." waitUntilDone:YES]; 48 49 NSArray *infos= [unzipFile listFileInZipInfos]; 50 for (FileInZipInfo *info in infos) { 51 NSString *fileInfo= [NSString stringWithFormat:@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level]; 52 [self performSelectorOnMainThread:@selector(log:) withObject:fileInfo waitUntilDone:YES]; 53 } 54 55 [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening first file..." waitUntilDone:YES]; 56 57 [unzipFile goToFirstFileInZip]; 58 ZipReadStream *read1= [unzipFile readCurrentFileInZip]; 59 60 [self performSelectorOnMainThread:@selector(log:) withObject:@"Reading from first file's stream..." waitUntilDone:YES]; 61 62 NSMutableData *data1= [[[NSMutableData alloc] initWithLength:256] autorelease]; 63 int bytesRead1= [read1 readDataWithBuffer:data1]; 64 65 BOOL ok= NO; 66 if (bytesRead1 == 3) { 67 NSString *fileText1= [[[NSString alloc] initWithBytes:[data1 bytes] length:bytesRead1 encoding:NSUTF8StringEncoding] autorelease]; 68 if ([fileText1 isEqualToString:@"abc"]) 69 ok= YES; 70 } 71 72 if (ok) 73 [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of first file is OK" waitUntilDone:YES]; 74 else 75 [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of first file is WRONG" waitUntilDone:YES]; 76 77 [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing first file's stream..." waitUntilDone:YES]; 78 79 [read1 finishedReading]; 80 81 [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening second file..." waitUntilDone:YES]; 82 83 [unzipFile goToNextFileInZip]; 84 ZipReadStream *read2= [unzipFile readCurrentFileInZip]; 85 86 [self performSelectorOnMainThread:@selector(log:) withObject:@"Reading from second file's stream..." waitUntilDone:YES]; 87 88 NSMutableData *data2= [[[NSMutableData alloc] initWithLength:256] autorelease]; 89 int bytesRead2= [read2 readDataWithBuffer:data2]; 90 91 ok= NO; 92 if (bytesRead2 == 3) { 93 NSString *fileText2= [[[NSString alloc] initWithBytes:[data2 bytes] length:bytesRead2 encoding:NSUTF8StringEncoding] autorelease]; 94 if ([fileText2 isEqualToString:@"XYZ"]) 95 ok= YES; 96 } 97 98 if (ok) 99 [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of second file is OK" waitUntilDone:YES]; 100 else 101 [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of second file is WRONG" waitUntilDone:YES]; 102 103 [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing second file's stream..." waitUntilDone:YES]; 104 105 [read2 finishedReading]; 106 107 [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing zip file..." waitUntilDone:YES]; 108 109 [unzipFile close]; 110 [unzipFile release]; 111 112 [self performSelectorOnMainThread:@selector(log:) withObject:@"Test terminated succesfully" waitUntilDone:YES]; 113 114 } @catch (ZipException *ze) { 115 [self performSelectorOnMainThread:@selector(log:) withObject:@"Caught a ZipException (see logs), terminating..." waitUntilDone:YES]; 116 117 NSLog(@"ZipException caught: %d - %@", ze.error, [ze reason]); 118 119 } @catch (id e) { 120 [self performSelectorOnMainThread:@selector(log:) withObject:@"Caught a generic exception (see logs), terminating..." waitUntilDone:YES]; 121 122 NSLog(@"Exception caught: %@ - %@", [[e class] description], [e description]); 123 } 124 125 [pool drain]; 126 }
转载于:https://www.cnblogs.com/GoGoagg/archive/2012/12/11/2813031.html
开源项目objective-zip相关推荐
- android zip 开源 加密,Android带密码解压----Zip4J开源项目使用
最近工作过程中,需要在Android项目中对一个带密码的压缩文件进行解压 ,之前就知道Java API中提供了 java.util.zip.*;包来支持Java对于压缩文件的相关压缩,解压缩操作.所以 ...
- android开源项目收集
9 开源项目 11.1 UI控件类开源项目 11.1.1 ListView篇 资料转载地址:https://github.com/Trinea/android-open-project 1. ...
- GitHub上Swift开源项目!
swift-open-project 这里汇集了目前为止最为流行的Swift开源项目,选取SwiftGuide中的开源部分,这里将每周对项目进行总结,如果大家有推荐的可以联系thinkloki@gma ...
- xmpp 开源项目选择_如何选择和维护安全的开源项目
xmpp 开源项目选择 评估开源项目安全性的一些技巧. (A few tricks for assessing the security of an open source project.) The ...
- 精选机器学习开源项目Top10
作者 | Mybridge 译者 | linstancy 编辑 | Jane 出品 | AI科技大本营 [导读]过去一个月里,我们对近 250 个机器学习开源项目进行了排名,并挑选出热度前 10 的项 ...
- Android开源项目源码下载(不断更新中)
原文地址:http://www.cnblogs.com/salam/archive/2010/10/26/1861779.html 最近我搜集了一些提供源码的开源项目,在这里发布出来供大家学习使用. ...
- 各种好的开源项目-转载
1,豆瓣相册https://github.com/TonnyTao/DoubanAlbum 2,voa在线英语https://github.com/cubewang/NewsReader 3,电竞第一 ...
- VC++、MFC最好的开源项目
介绍:介绍一下用VC++/MFC写的最好的开源项目. Sourceforge.net中有许多高质量的VC++开源项目,我列举了一些可以作为VC++程序员的参考. 正文: VC++.MFC中最好的开源项 ...
- Android开源项目分类汇总-转载
太长了,还是转载吧... 今天在看博客的时候,无意中发现了@Trinea在GitHub上的一个项目Android开源项目分类汇总,由于类容太多了,我没有一个个完整地看完,但是里面介绍的开源项目都非常有 ...
- Android开源项目分类汇总[转]
Android开源项目分类汇总 如果你也对开源实现库的实现原理感兴趣,欢迎 Star 和 Fork Android优秀开源项目实现原理解析 欢迎加入 QQ 交流群:383537512(入群理由需要填写 ...
最新文章
- Rancher使用入门
- 利用virtualenv和pip构建虚环境并安装配置推送客户端
- node中npm安装模块的网络问题
- linux笔记:shell基础-bash基本功能
- 远程桌面时提示凭证不工作问题的终极解决办法
- 开篇-----勉励篇
- SQL 必知必会·笔记3过滤数据
- vs2005常用快捷键_包括代码自动缩进
- 一个简单 JDK 动态代理的实例
- 【BLE MIDI】MIDI 文件格式分析 ( MIDI 文件头解析 | MIDI 文件头标识 | MIDI 文件头长度 | MIDI 文件格式 | MIDI 轨道个数 | 基本时间 )
- 分区分服游戏框架设计
- JAVA中操作数据库方式与设计模式的应用 --青山不改绿水长流-EKing
- java重构工具_Piranha(陈旧代码自动重构工具)
- DVWA 不跳转_终于开通!小红书图文、直播可跳转淘宝链接!
- 五、C语言指针和数组
- kaggle:谁是NBA最佳防守球员?(二)
- 【XSY3126】异或II 数学
- 创建跨账户IAM角色访问(Creating Cross-Account IAM Roles)
- (纪中)2419. Grass Planting
- wap网站服务器要求,使您的WEB服务器支持WAP数据发送
热门文章
- MySQL进阶13--常见六大约束: 非空/默认/主键/唯一约束/检查约束/外键约束--表级约束 / 列级约束...
- 使用CSS创建Digg样式风格的导航栏或菜单
- H5(仅仅是个地址)
- JavaScript课堂笔记!
- Android---------------Handler的学习
- 自动生成mybatis代码
- C++的四种强制转型形式:
- SPOJ Play on Words
- PHP漏洞全解(三)-客户端脚本植入
- 处理2D图像和纹理——旋转,缩放和镜像一张图像