1

Possible Duplicate:
How to uncompress a gzip file and write that out to an uncompressed file, on iPhone

Im trying to unzip a .gz sqlite file in iOS, but until now I did not found a good library for that.

I tried SSZipArchive like that:

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];

That works for a zipped sqlite database file, but not if I gzip the sqlite database. Then everytime the error "cant open zip file" is returning.

Then I tried this GZIP approach from https://github.com/nicklockwood/GZIP. I used the code like that:

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]; 

After that I got a file named test.sqlite in my Documents folder, but if I try to open it, it fails because the fail is corrupt.

And my last try was ZipArchive from http://code.google.com/p/ziparchive/. I used it like that:

ZipArchive* za = [[ZipArchive alloc] init];
if( [za UnzipOpenFile:path] ){
    BOOL success = [za UnzipFileTo:destination overWrite:YES];
    [za UnzipCloseFile];
    return success;
}

But this also cant open the file.

Can someone help me?

Community
  • 1
  • 1
NDY
  • 3,527
  • 4
  • 48
  • 63

1 Answers1

1

There is zlib library use can add to your target in linker settings in Xcode.

Here you can find example on how to use zlib. http://zlib.net/zlib_how.html

Ivor Prebeg
  • 988
  • 6
  • 11