简体   繁体   中英

How can I save multiple files from an NSData object?

So I have a zip file, which gets extracted using Objective-Zip. The extracted contents then get put into an NSData object. I want to save the contents into the apps Documents folder. The problem is these are multiple files, and writeToFile:atomically: saves the contents of the zip into one file.

Any ideas? The other question I saw just said to use ZipArchive.

I need help fast, because the app needs to be finished by the end of my work tomorrow.

I think you need to use ZipArchive:

ZipArchive* za = [[ZipArchive alloc] init];
NSData *Data = [NSData  dataWithContentsOfURL:url]; // here url is your zip url
NSArray *documentPathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirString = [documentPathArray objectAtIndex:0];
NSString *filePath = [documentsDirString stringByAppendingPathComponent:@"temp.zip"];

NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSError *writeError = nil;
[Data writeToURL: fileURL options:0 error:&writeError];
if( writeError) {
   NSLog(@" Error in writing file %@' : \n %@ ", filePath , writeError );
   return;
}
if( [za UnzipOpenFile:filePath] )
{

    BOOL ret = [za UnzipFileTo:documentsDirz overWrite:YES];
    if( NO==ret )
     {
      NSLog(@"NO");
    }
    [za UnzipCloseFile];
} 

for more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM