How to unzip the downloaded file into the document directory

I was looking for unpacking a ZIP file that is being loaded into the document directory. but I only found questions about them, and I did not get any suitable answer that matches my request.

Each of them suggests downloading an api file called "MiniZip" and using it. but its bulky code and a lot of code are not needed for me. So, it would be great if I got less code to unzip the file and use it. Its receipt is downloaded from the url exactly the same as it was saved, but I don't get how to unzip and use it in the document directory. can someone please help me by providing some sample code or suggesting to me ..

The following code is the code to download 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];
}   
+3
source share
1 answer

Does MiniZip have any performance issues?

If not, check objective-zip .

+2
source

Source: https://habr.com/ru/post/1782483/


All Articles