iOS文件壓縮與解壓縮,ZipArchive使用

1. 導入三方包

包地址:
https://github.com/ZipArchive/ZipArchive
或者通過pod加載

pod 'SSZipArchive’

2. 使用

路徑宏定義,方便使用

#define doc_path(_fileOrFolder_) [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:_fileOrFolder_]

NSString *zippath = doc_path(@"zipfile.zip");//創建壓縮文件路徑

壓縮,傳入被壓縮和壓縮後文件的路徑

+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths

例如

[SSZipArchive createZipFileAtPath:zippath withFilesAtPaths:@[txtPath]];

解壓縮,傳入被解壓和解壓後文件路徑

+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章