iOS開發 檔案壓縮與解壓縮

2021-07-02 18:27:08 字數 2665 閱讀 8165

注意:需要引入libz.dylib框架 

[ssziparchive createzipfileatpath:zippedpath withfilesatpaths:inputpaths];一、技術方案 

1.第三方框架:ssziparchive 

2.依賴的動態庫:libz.dylib

二、壓縮1 

1.第乙個方法 

/** 

zipfile :產生的zip檔案的最終路徑 

directory : 需要進行的壓縮的資料夾路徑 

*/

[ssziparchive createzipfileatpath:zipfile withcontentsofdirectory:directory]

;

[ssziparchive createzipfileatpath:zipfile withfilesatpaths:files]

;

三、解壓縮 

/** 

zipfile :需要解壓的zip檔案的路徑 

dest : 解壓到什麼地方 

*/

[ssziparchive unzipfileatpath:zipfile todestination:dest]

;

#import "maljobviewcontroller.h"

#import "ssziparchive.h"

#define maljobfileboundary @"heima"

#define maljobnewline @"\r\n"

#define maljobencode(str) [str datausingencoding:nsutf8stringencoding]

@inte***ce

maljobviewcontroller ()

@end

@implementation

maljobviewcontroller

- (void)viewdidload

- (nsstring *)mimetype:(nsurl *)url

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event

]; }

}- (void)upload:(nsstring *)filename mimetype:(nsstring *)mimetype filedata:(nsdata *)filedata params:(nsdictionary *)params

]; // 3.3.結束標記

// 4.設定請求頭(告訴伺服器這次傳給你的是檔案資料,告訴伺服器現在傳送的是乙個檔案上傳請求)

// 5.傳送請求

[nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue mainqueue] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) ];

}@end

#import "maljobviewcontroller.h"

#import "ssziparchive.h"

@implementation

maljobviewcontroller

- (void)viewdidload

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event

]; [task resume];

}@end

iOS檔案的壓縮與解壓縮

一 技術依賴 1.第三方框架 sssziparchive 2.依賴的動態庫 libz.dylib 二 壓縮 1.第一種方法 zipfile 產生的zip檔案的最終路徑 directory 需要進行的壓縮的資料夾路徑 ssziparchive createzipfileatpath zipfile w...

檔案壓縮與解壓縮

類 zipfile 構造方法 zipfile file file 開啟供閱讀的zip檔案,由指定的file物件給出。zipfile file file,int mode 開啟新的zipfile以使用指定模式從指定file物件讀取 zipfile string name 開啟zip檔案進行閱讀 方法摘...

檔案壓縮與解壓縮

public class zipfileutil zipoutputstream zostream null fileinputstream fistream null fileoutputstream fostream null try zostream.closeentry issuccess ...