可能重复:
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