3 回答

TA貢獻1850條經驗 獲得超11個贊
我想要一個簡單的解決方案,但在這里找不到我喜歡的解決方案,因此我修改了一個庫以實現自己想要的功能。您可能會發現SSZipArchive有用。(它也可以順便創建zip文件。)
用法:
NSString *path = @"path_to_your_zip_file";
NSString *destination = @"path_to_the_folder_where_you_want_it_unzipped";
[SSZipArchive unzipFileAtPath:path toDestination:destination];

TA貢獻1828條經驗 獲得超3個贊
對于gzip,這段代碼對我來說效果很好:
數據庫是這樣準備的:gzip foo.db
關鍵是遍歷gzread()。上面的示例僅讀取前CHUNK字節。
#import <zlib.h>
#define CHUNK 16384
NSLog(@"testing unzip of database");
start = [NSDate date];
NSString *zippedDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"foo.db.gz"];
NSString *unzippedDBPath = [documentsDirectory stringByAppendingPathComponent:@"foo2.db"];
gzFile file = gzopen([zippedDBPath UTF8String], "rb");
FILE *dest = fopen([unzippedDBPath UTF8String], "w");
unsigned char buffer[CHUNK];
int uncompressedLength;
while (uncompressedLength = gzread(file, buffer, CHUNK) ) {
// got data out of our file
if(fwrite(buffer, 1, uncompressedLength, dest) != uncompressedLength || ferror(dest)) {
NSLog(@"error writing data");
}
}
fclose(dest);
gzclose(file);
NSLog(@"Finished unzipping database");
順便說一句,我可以在77秒內將33MB解壓縮到130MB,或者每秒壓縮約1.7MB。
- 3 回答
- 0 關注
- 562 瀏覽
添加回答
舉報