用于从 Cocoa 应用程序浏览 zip 文件的库

发布于 2024-12-04 06:46:57 字数 1539 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慕烟庭风 2024-12-11 06:46:57

http://code.google.com/p/objective-zip/

读取文件

ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
[unzipFile goToFirstFileInZip];

ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];

[read finishedReading];
[zipFile close];

列出内部文件

ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
NSArray *infos= [unzipFile listFileInZipInfos];
for (FileInZipInfo *info in infos) {
        NSLog(@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level);

        // Locate the file in the zip
        [unzipFile locateFileInZip:info.name];

        // Expand the file in memory
        ZipReadStream *read= [unzipFile readCurrentFileInZip];
        NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
        int bytesRead= [read readDataWithBuffer:data];
        [read finishedReading];
}
[zipFile close];

有关目录结构的注意事项

请注意,zip 文件内部没有文件文件夹层次结构的表示:它只是嵌入文件名中(即:名称类似于x/y/z/file.txt)。由提取文件的程序将这些文件名视为表达结构并在文件系统上重建它(在创建过程中反之亦然)。常见的拉链/解拉链器只是遵循这个规则。

来自手册

http://code.google.com/p/objective-zip/

Read file out

ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
[unzipFile goToFirstFileInZip];

ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];

[read finishedReading];
[zipFile close];

List files inside

ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
NSArray *infos= [unzipFile listFileInZipInfos];
for (FileInZipInfo *info in infos) {
        NSLog(@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level);

        // Locate the file in the zip
        [unzipFile locateFileInZip:info.name];

        // Expand the file in memory
        ZipReadStream *read= [unzipFile readCurrentFileInZip];
        NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
        int bytesRead= [read readDataWithBuffer:data];
        [read finishedReading];
}
[zipFile close];

Note about direcotry structure

Please note that inside the zip files there is no representation of a file-folder hierarchy: it is simply embedded in file names (i.e.: a file with a name like x/y/z/file.txt). It is up to the program that extracts the files to consider these file names as expressing a structure and rebuild it on the file system (and viceversa during creation). Common zippers/unzippers simply follow this rule.

from manual

江挽川 2024-12-11 06:46:57

请参阅 LOZIPFileWrapper

    LOZIPFileWrapper *zipFileWrapper = [[LOZIPFileWrapper alloc] initWithURL:URL password:nil error:NULL];
    NSArray *contentsOfZipArchive = [zipFileWrapper contentOfZIPFileIncludingFolders:YES error:NULL];
    NSData *content = [zipFileWrapper contentsAtPath:contentsOfZipArchive[0] error:NULL];

See LOZIPFileWrapper:

    LOZIPFileWrapper *zipFileWrapper = [[LOZIPFileWrapper alloc] initWithURL:URL password:nil error:NULL];
    NSArray *contentsOfZipArchive = [zipFileWrapper contentOfZIPFileIncludingFolders:YES error:NULL];
    NSData *content = [zipFileWrapper contentsAtPath:contentsOfZipArchive[0] error:NULL];
怪我闹别瞎闹 2024-12-11 06:46:57

您可以使用 Marek Sebera 的想法,但您可以首先列出 zip 文件内容:

想法一:
- 只需获取原始标题列表(使用上述想法)并拥有 UITableView
- 选择标题后,从 uitableview 获取 zip 中的文件编号,然后将其解压

文件名示例:
哈哈.txt
路径/hello.doc
path/dir/lol/file.txt

想法二:
- 解档到某个地方(比如库目录)
- 当用户完成后,重新压缩

You could use Marek Sebera's idea, but you could start by listing the zip file contents:

Idea One:
- just get a list of the raw titles (use the above idea) and have a UITableView
- When a title is selected, get the file's number in the zip from the uitableview, then unarchive it

Example of filenames:
lol.txt
path/hello.doc
path/dir/lol/file.txt

Idea Two:
- unarchive to somewhere (like the library dir)
- when the user finishes, re-compress

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文