可能重複:
How to uncompress a gzip file and write that out to an uncompressed file, on iPhone的iOS解壓。廣州文件
我試着去解壓縮iOS中加上.gz sqlite的文件,但到現在爲止我沒有找到一個好的圖書館爲。
我想SSZipArchive
這樣的:
path = [[NSBundle bundleForClass:[self class]] pathForResource:@"test.sqlite" ofType:@"gz"];
NSString *documentsDir = (NSString *)[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
destination = documentsDir;
NSError *error;
BOOL success = [SSZipArchive unzipFileAtPath:path toDestination:destination overwrite:YES password:nil error: &error];
,對於壓縮的SQLite數據庫文件的工作,但如果我gzip壓縮SQLite數據庫。然後每次錯誤「無法打開zip文件」正在恢復。
然後我嘗試這種方法GZIP
從https://github.com/nicklockwood/GZIP。 我用這樣的代碼:
path = [[NSBundle bundleForClass:[self class]] pathForResource:@"test.sqlite" ofType:@"gz"];
NSString *documentsDir = (NSString *)[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
destination = [documentsDir stringByAppendingPathComponent:@"test.sqlite"];
NSData *gzData = [NSData dataWithContentsOfFile:path];
NSData *ungzippedData = [gzData gunzippedData];
return [ungzippedData writeToFile:destination atomically:YES];
之後,我在我的文檔文件夾中有一個名爲test.sqlite文件,但如果我嘗試打開它,它失敗,因爲失敗是腐敗。
而我的最後一次嘗試是ZipArchive
從http://code.google.com/p/ziparchive/。 我用它這樣的:
ZipArchive* za = [[ZipArchive alloc] init];
if([za UnzipOpenFile:path]){
BOOL success = [za UnzipFileTo:destination overWrite:YES];
[za UnzipCloseFile];
return success;
}
但是,這也不能打開該文件。
有人可以幫助我嗎?
您好安迪,我面對我的app.have同樣的問題,你解決這個問題? – Smita