如何使用ZipKit在iOS中压缩目录? [英] How to zip a directory in iOS with ZipKit?

查看:344
本文介绍了如何使用ZipKit在iOS中压缩目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在iOS应用中压缩我的Documents文件夹的子目录。在咨询Google和其他SO帖子后,我发现ZipKit和ZipArchive是两个提供此功能的开源项目。在这一点上,我选择实现ZipKit,因为它似乎比ZipArchive保持更新。

I need to zip a subdirectory of my Documents folder in an iOS app. After consulting Google and other SO posts, I've found ZipKit and ZipArchive as two open source projects offering this functionality. At this point, I've chosen to implement ZipKit, as it seems to be much more currently maintained than ZipArchive.

我找到了如何解压缩档案的例子,但是无法找到如何将目录存档到.zip文件中的示例。我尝试了以下代码,它返回了一个成功的结果状态,但实际上没有生成zip文件。

I've found examples of how to unzip archives, but haven't been able to find an example of how to archive a directory into a .zip file. I have tried the following code, which returned a successful result status, but no zip file was actually generated.

// projectPath is /Documents/projects/myproject
ZKDataArchive *archive = [[ZKDataArchive alloc] init];
NSInteger result = [archive deflateDirectory:projectPath relativeToPath:nil usingResourceFork:NO];

我确定有一些基本的东西我做得不对,但是还没能弄清楚它是什么。特别是,我还没有弄清楚deflateDirectory的每个参数的含义:。

I'm sure there's something basic I'm not doing correctly, but haven't been able to sort out what it is. In particular, I haven't yet figured out the meaning of each parameter to deflateDirectory:.

如果有人能指出我正确的方向(或者有其他建议用于压缩) iOS上的目录)我将非常感激。

If anyone can point me in the right direction (or has other recommendations for zipping directories on iOS) I would greatly appreciate it.

谢谢!

推荐答案

成功。这是其他人的独家新闻:

Success. Here's the scoop for anyone else:

假设我们想要压缩/ Documents / myfolder

Let's say we want to zip /Documents/myfolder

NSString *zipFilePath = @"/Documents/zipped.zip";
ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:zipFilePath];
NSInteger result = [archive deflateDirectory:@"/Documents/myfolder" relativeToPath:@"/Documents" usingResourceFork:NO];

并创建了zip文件!

这篇关于如何使用ZipKit在iOS中压缩目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆