使用 ZIP 存档来存储 NSDocument 数据

发布于 2024-08-10 22:29:01 字数 386 浏览 7 评论 0原文

我注意到 Apple 开始使用 zip 存档来替换 iWork 应用程序中的文档包(在 Finder 中显示为单个文件的文件夹)。我正在考虑做同样的事情,因为我不断收到与我的文档包复制到 Windows 文件服务器时损坏相关的支持电子邮件。

我的问题是在基于 NSDocument 的应用程序中执行此操作的最佳方法是什么?

我想最简单的方法是创建一个目录文件包装器,创建它的存档并将其返回到 NSDocument 中,

- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError **)outError

但我无法理解如何创建 NSFileWrapper 的 zip 存档。

I noticed that Apple started using zip archives to replace document packages (folders appearing as a single file in Finder) in the iWork applications. I'm considering doing the same as I keep getting support emails related to my document packages getting corrupted when copying them to a windows fileserver.

My questions is what would be the best way to do this in a NSDocument-based application?

I guess the easiest way would be to create a directory file wrapper, create an archive of it and return it in NSDocument's

- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError **)outError

But I fail to understand how to create a zip archive of the NSFileWrapper.

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

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

发布评论

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

评论(4

泪痕残 2024-08-17 22:29:01

如果您只想将 zip 文件设为您的格式(即“mydoc.myextension”实际上是一个 zip 文件),则没有方便的内置 Cocoa 机制来使用代码创建 zip 存档。看看这个 Google 代码项目:ziparchive 我不相信文件包装器会有帮助但在这种情况下。

由于您引用了 iWork,我没有 iWork 09,但以前的版本使用包格式(即 NSFileWrapper 是理想的),但压缩描述文档结构的 XML,同时保留附件(如嵌入媒体、图像等)。 )在资源文件夹中,全部在包内。我认为他们这样做是因为 XML 对于大型、复杂的文档来说可能相当大,但由于它是文本,所以压缩得很好。这会导致文档整体变小。

如果苹果确实已经将整个文档制作为一个大的 zip 存档(我觉得很奇怪),他们要么将必要的资源提取到某个临时文件夹中,要么将整个文档加载到内存中(从他们的包中倒退了一步 -基于方法,IMO)。这些也是您需要考虑的因素。

If you just want to make a zip file your format (ie, "mydoc.myextension" is actually a zip file), there's no convenient, built-in Cocoa mechanism for creating zip archives with code. Take a look at this Google Code project: ziparchive I don't believe a file wrapper will help in that case, though.

Since you cited iWork, I don't own iWork 09, but previous versions use a package format (ie, NSFileWrapper would be ideal) but zip the XML that describes the document's structure, while keeping attachments (like embedded media, images, etc.) in a resource folder, all within the package. I assume they do this because XML can be quite large for large, complicated documents, but compresses very well because it's text. This results in an overall smaller document.

If indeed Apple has moved to making the entire document one big zip archive (which I would find odd), they'd either be extracting necessary resources to a temp folder somewhere or loading the whole thing into memory (a step backward from their package-based approach, IMO). These are considerations you'll need to take into account as well.

眼眸里的那抹悲凉 2024-08-17 22:29:01

我知道这有点晚了,但我想我会提供另一个链接,可以帮助任何遇到这篇文章的人。

看起来 Apple 的 ZipBrowser 示例将是一个好的开始 http: //developer.apple.com/library/mac/#samplecode/ZipBrowser/Introduction/Intro.html

HTH

I know this is a little late to the party but I thought I'd offer up another link that could help anyone that comes across this post.

Looks like the ZipBrowser sample from Apple would be a good start http://developer.apple.com/library/mac/#samplecode/ZipBrowser/Introduction/Intro.html

HTH

走走停停 2024-08-17 22:29:01

您需要从文件包装器中获取数据并将其输入到 ziparchive 之类的内容中。

You’ll want to take the data from the file wrapper and feed it into something like ziparchive.

把时间冻结 2024-08-17 22:29:01

Pierre-Olivier Latour 编写了一个处理 zip 压缩的 NSData 扩展。您可以在此处获取:http://code.google.com/p/polkit/

Pierre-Olivier Latour has written an extension to NSData that deals with zip compression. You can get it here: http://code.google.com/p/polkit/

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