我有一个应用程序,其中解压缩.gz文件,它在iOS 7上运行正常,当我在iOS 8中尝试相同时,我面临解压缩的问题,zlib.h的gzopen总是为零。这是代码:
(void)unzipFileCustom
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* dPath = [paths objectAtIndex:0];
NSString* zippedDBPath = [dPath stringByAppendingPathComponent:@"test.sqlite.gz"] ;
NSString *unzippedDBPath = [dPath stringByAppendingPathComponent:@"test.sqlite"];
//gzfile is always nil
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");
}