I searched for unzipping the .zip file which is downloaded in the document directory. but i found only questions about them and i didnt get any suitable answer which suits my query.
Every one is suggesting to download some api file called “MiniZip” and make use of that. but Its bulky code and that much code is not needed for me. So, it would be greatful for me if i get some less code to unzip the file and make use of it. Its getting downloaded from the url exactly as it was stored but im not getting how to unzip and make use of it in the documents directory. can any one please help me out by giving some sample code or suggesting me..
The following code is the code for downloading my zip file using the url.
-(IBAction)download:(id)sender{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://some url contains .zip file"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Inform the user that the download failed.
recievedData=[[NSMutableData data ]retain];
// [recievedData writeToFile:path atomically:YES];
NSLog(@"download ");
}
else {
NSLog(@"download fail");
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[recievedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[recievedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
[connection release];
[recievedData release];
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[recievedData length]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path=[documentsDirectory stringByAppendingPathComponent:@"books"];
NSLog(@"value of the path is:%@",path);
[recievedData writeToFile:[path stringByAppendingPathComponent:@"file"] atomically:YES];
[connection release];
[recievedData release];
}
Does MiniZip present any performance problems to you at all?
If it doesn’t, then check out objective-zip.