ZipPinch 0.1.3

ZipPinch 0.1.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2014年12月

Alexey Bukhtin维护。



ZipPinch 0.1.3

恢复了pinch-objc

ZipPinch — 远程处理zip文件。它读取zip文件内容而无需自行下载,并解压您需要的文件。

注意:ZipPinch与AFNetworking 1.3+兼容。

安装

  1. Pods: pod ZipPinch
  2. ZipPinch/ZipPinch/*.{h,m}中的文件复制到您的项目中。

使用方法

1. 使用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];
        }];
    }
}];

2. 使用带有文件缓存和输出中的NSDataZPManager

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

3. 尝试演示: pod try ZipPinch

待办事项

  1. AFNetworking 2.0
  2. 错误处理。