Cocoa中Zip歸檔讀寫框架
Cocoa中Zip歸檔讀寫框架是本文要介紹的內容,主要介紹一個zip讀寫框架:zip-framework。這個框架支持直接在程序中讀寫zip歸檔中的文件,而無需使用NSTask去執行命令行的unzip。
Cocoa并沒有提供讀寫zip的功能(有GZIP: /usr/include/zlib.h,但是很有局限性),這個zip框架很好地實現了這一功能。這個框架使用Objective-C寫成,因此可以非常方便地在程序中調用。理論上來講也完全可以用于iPhone(如果誰有興趣可以試一下)。
使用方法:
- #import <stdio .h>
- #import <zip /ZipArchive.h>
- ZipArchive *zip = [[ZipArchive alloc] initWithFile:@"…"];
- if (!zip) {
- NSLog(@"File could not be opened");
- }
- FILE *fp = [zip entryNamed:@"README.txt"]; // open stream to file README.txt in archive
- if (!fp) {
- NSLog(@"Not a file or not available in the archive");
- }
- NSArray *allEntries = [zip entries];
- // for example: [@"README", @"COPYING", @"src/", @"src/main.c"]
- [zip release];
- // Autoreleased version
- ZipArchive *autoreleasedZip = [ZipArchive archiveWithFile:@"…"];
- </zip></stdio>
這樣就可以獲取到zip包中的文件指針,可以直接對其進行讀操作。(目前只支持fread操作)
小結:Cocoa中Zip歸檔讀寫框架的內容介紹完了,希望本文對你有所幫助!
下載地址位于:http://code.google.com/p/zip-framework/