0

I'd like my app to decompress and handle the contents of zip files.

I'm trying to do this the Cocoa way, without using external libraries, so I'm turning to NSKeyedUnarchiver and here's my code:

-(void) unarchive{

    NSString *outputDirectory = [[NSHomeDirectory() stringByAppendingString:@"/Documents/"] stringByAppendingString:@"TheNewFolderName/"];
    NSLog(@"Output Directory: %@", outputDirectory);

    //MyArchive.zip is the filename of the zip file I placed in Xcode
    NSData *theArchive = [NSKeyedUnarchiver unarchiveObjectWithFile:@"MyArchive.zip"];

    NSError *error;
    [theArchive writeToFile:outputDirectory options:NSDataWritingAtomic error:&error];

    NSLog(@"theArchive is %@", theArchive);

And this prints "theArchive is null"! What am I doing wrong..?

Eric
  • 16,003
  • 15
  • 87
  • 139

1 Answers1

0

NSKeyedArchiver and NSKeyedUnarchiver are used for archiving and unarchiving objects (NSObject subclasses, with certain restrictions) in your application. I'm afraid you cannot use it with zip files.

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • Indeed... This works for me: http://stackoverflow.com/questions/5385480/iphone-downloding-zip-and-extracting-in-main-bundle-subdirectory-at-runtime But... So the only way to decompress a zip file at runtime is to use a third-party library? – Eric Jun 08 '12 at 13:32