iOS 數(shù)據(jù)壓縮與解壓
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供東海網(wǎng)站建設(shè)、東海做網(wǎng)站、東海網(wǎng)站設(shè)計(jì)、東海網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、東海企業(yè)網(wǎng)站模板建站服務(wù),10余年東海做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
Hi,推薦文件給你 "數(shù)據(jù)壓縮與解壓.zip"
http://vdisk.weibo.com/s/Gbabp
本文中需要的第三庫(kù)在本文的代碼例子中可以下載。minizip和ZipArchive這兩個(gè)第三庫(kù)
ViewController.h代碼如下:
#import <UIKit/UIKit.h> #import "ZipArchive.h" @interface ViewController : UIViewController -(IBAction)compress:(id)sender; -(IBAction)unAr:(id)sender; @end
ViewController.m代碼如下:
自己拖2個(gè)Button與如下兩個(gè)方法相關(guān)聯(lián)
//這方法中數(shù)據(jù)壓縮的方法:
-(IBAction)compress:(id)sender { //導(dǎo)入ZipArchive包之后要加入libz.1.2.5.dylib的庫(kù) ZipArchive* zip = [[ZipArchive alloc] init]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; NSString* zipfilePath = [documentpath stringByAppendingString:@"/dj.zip"] ; // NSLog(@"%@",zipfilePath); NSString* p_w_picpath2 = [[NSBundle mainBundle] pathForResource:@"xiaonan" ofType:@"jpg"]; NSString* p_w_picpath3 = [[NSBundle mainBundle] pathForResource:@"xiaonan" ofType:@"jpg"]; //創(chuàng)建壓縮包 BOOL ret = [zip CreateZipFile2:zipfilePath]; //向壓縮包內(nèi)加入數(shù)據(jù) ret = [zip addFileToZip:p_w_picpath2 newname:@"xiaonan.jpg"]; ret = [zip addFileToZip:p_w_picpath3 newname:@"p_w_picpath3.jpg"]; //關(guān)閉壓縮包 [zip CloseZipFile2]; [zip release]; }
//數(shù)據(jù)解壓的方法
-(IBAction)unAr:(id)sender { 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:@"/dj.zip"] ; NSString* unzipto = [documentpath stringByAppendingString:@"/dj"] ; //找到需要解壓文件的路徑 if( [zip UnzipOpenFile:l_zipfile] ) { BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES]; if( NO==ret ) { } //完成解壓 [zip UnzipCloseFile]; } [zip release]; }
當(dāng)前標(biāo)題:iOS數(shù)據(jù)壓縮與解壓
當(dāng)前地址:http://www.rwnh.cn/article34/psghse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、標(biāo)簽優(yōu)化、網(wǎng)站策劃、網(wǎng)站排名、App開(kāi)發(fā)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)