Simplest way on iPhone to unzip downloaded file?

Posted by Scott Pendleton on Stack Overflow See other posts from Stack Overflow or by Scott Pendleton
Published on 2010-03-24T05:16:25Z Indexed on 2010/03/24 5:23 UTC
Read the original article Hit count: 613

Filed under:
|

Goal: download a zipped file, unzip it, and save it in the iPhone app's Documents directory.

The following code makes use of the initWithGzippedData method that was added to NSData in the Molecule app found here: http://www.sunsetlakesoftware.com/molecules

As adapted to my app:

NSString *sFolder = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *sFileName = [sFolder stringByAppendingPathComponent:@"MyFile.db"]; NSURL *oURL = [NSURL URLWithString: @"http://www.isystant.com/Files/MyFile.zip"]; NSData *oZipData = [NSData dataWithContentsOfURL: oURL]; NSData *oData = [[NSData alloc] initWithGzippedData:oZipData]; [oZipData release]; b = [oData writeToFile:sFileName atomically:NO]; NSLog(@"Unzip %i", b);

Result: A zip file is successfully downloaded. From it a new, supposedly unzipped file is created in the Documents directory with the desired name (MyFile.db) but it has zero bytes.

Anybody see the problem? Or else is there a simpler way to unzip a downloaded file than the one used in the Molecules app?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about gzip