在iOS 8中解压缩.gz文件

时间:2014-10-09 13:17:48

标签: ios8 gzip

我有一个应用程序,其中解压缩.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");
}

0 个答案:

没有答案