gpt4 book ai didi

iphone - 如何将下载的文件解压到文档目录

转载 作者:搜寻专家 更新时间:2023-10-30 20:23:08 24 4
gpt4 key购买 nike

我搜索解压缩文档目录中下载的 .zip 文件。但我只发现了有关它们的问题,但没有得到适合我的查询的任何合适答案。

每个人都建议下载一些名为“MiniZip”的 api 文件并加以利用。但是它的代码很笨重,而且我不需要那么多代码。所以,如果我能得到一些更少的代码来解压缩文件并使用它,那对我来说会很棒。它是从 url 下载的,与存储时完全一样,但我不知道如何在文档目录中解压缩和使用它。任何人都可以通过提供一些示例代码或建议我来帮助我..

以下代码是使用 url 下载我的 zip 文件的代码。

-(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];
}

最佳答案

MiniZip 是否给您带来任何性能问题?

如果没有,请查看 objective-zip .

关于iphone - 如何将下载的文件解压到文档目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4548256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com