Thursday, August 12, 2010

unzip data from web

NSString *aDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];


NSFileManager *fileManager= [NSFileManager defaultManager];

NSString* filePath = [NSString stringWithFormat:@"%@/temp.zip", aDirectory];
NSString* updateURL = @"http://localhost/list.zip";
NSLog(@"Checking update at : %@", updateURL);
NSData* updateData = [NSData dataWithContentsOfURL: [NSURL URLWithString: updateURL] ];

[fileManager createFileAtPath:filePath contents:updateData attributes:nil];

ZipArchive *zipArchive = [[ZipArchive alloc] init];

if([zipArchive UnzipOpenFile:filePath]) {

if ([zipArchive UnzipFileTo:aDirectory overWrite:YES]) {
//unzipped successfully
NSLog(@"Archive unzip Success");
[fileManager removeItemAtPath:filePath error:NULL];
} else {
NSLog(@"Failure To Unzip Archive");
}

} else {
NSLog(@"Failure To Open Archive");
}

[zipArchive release];

NSLog(@"string text is %@",filePath);

No comments:

FEEDJIT Live