恢复了pinch-objc。
ZipPinch — 远程处理zip文件。它读取zip文件内容而无需自行下载,并解压您需要的文件。
注意:ZipPinch与AFNetworking 1.3+兼容。
pod ZipPinch
。ZipPinch/ZipPinch/*.{h,m}
中的文件复制到您的项目中。ZPArchive
。// URL with zip file: Top 100 Hubble photos.
NSURL *URL = [NSURL URLWithString:@"http://www.spacetelescope.org/static/images/zip/top100/top100-large.zip"];
// Create zip archive instance.
ZPArchive *archive = [ZPArchive new];
// Fetch zip contents with URL.
[archive fetchArchiveWithURL:URL completionBlock:^(long long fileLength, NSArray *entries) {
// Array containts ZPEntry objects.
// If entries not empty, get first item and unzip file.
ZPEntry *entry = [entries firstObject];
if (entry) {
// Unzip only one file.
[archive fetchFile:entry completionBlock:^(ZPEntry *entry) {
// Now entry with data if error not occurs.
// For example, create Image from entry data.
UIImage *image = [UIImage imageWithData:entry.data];
}];
}
}];
NSData
的ZPManager
。// URL with zip file: Top 100 Hubble photos.
NSURL *URL = [NSURL URLWithString:@"http://www.spacetelescope.org/static/images/zip/top100/top100-large.zip"];
// Create zip manager with URL.
ZPManager *zipManager = [[ZPManager alloc] initWithURL:URL];
// Enable file cache at default path: /Library/Caches/ZipPinch/.
[zipManager enableCacheAtPath:nil];
// Fetch zip contents with URL.
[zipManager loadContentWithCompletionBlock:^(long long fileLength, NSArray *entries) {
// Array containts ZPEntry objects.
// If entries not empty, get first item and unzip file.
ZPEntry *entry = [entries firstObject];
// Load data with entry.
[zipManager loadDataWithFilePath:entry.filePath completionBlock:^(NSData *data) {
// For example, create Image from entry data.
UIImage *image = [UIImage imageWithData:data];
}];
}];
// After loading zip contents we can use zipManager.entries property to unzip others files.
// If we know zip internal file structure, we can use URL to load data.
NSURL *imageURL = [URL URLByAppendingPathComponent:@"top100/heic1307.jpg"];
// Unzip image data with imageURL.
[zipManager loadDataWithURL:imageURL completionBlock:^(NSData *data) {
UIImage *image = [UIImage imageWithData:data];
}];
pod try ZipPinch