在 Objective C 中压缩文件夹

发布于 2024-10-03 22:54:38 字数 306 浏览 3 评论 0原文

Objective C 中是否有任何库可以用于压缩整个文件夹(并解压缩它们)?我通过搜索查看了其中一些,但它们看起来需要单独添加文件,其中一些据说会崩溃......

看起来这个库可能会工作: http://bitbucket.org/dchest/osxzip/overview

不知道是否支持然而,文件夹。有人知道它是否支持压缩文件夹或有其他库支持吗?即使是与命令行 libz 交互的示例代码对我来说也很好......

Are there any libraries that work in Objective C for zipping entire folders (and decompressing them)? I have looked at some of them by searching but they look like they require adding files individually and some of them supposedly crash...

It looks like this library might work:
http://bitbucket.org/dchest/osxzip/overview

I don't know if it supports folders, however. Anyone know if it does or have any other libraries that support zipping folders? Even sample code for interacting with the command line libz would be fine with me...

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

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

发布评论

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

评论(2

眼趣 2024-10-10 22:54:38

您可以使用 NSTask 来运行命令行同上程序。请务必查看 ditto 手册页,了解正确的标志组合,以获得与 Finder 兼容的压缩。

You could use NSTask to run the command line ditto program. Be sure to look at the ditto man page for the right combination of flags to get Finder-compatible zipping.

单调的奢华 2024-10-10 22:54:38

根据此示例: http:// www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app 你可以得到一个带有压缩数据的 NSData 对象,然后用 [data writeToFile.. ..]

- (NSData *)exportToNSData {
    NSError *error;
    NSURL *url = [NSURL fileURLWithPath:_docPath];
    NSFileWrapper *dirWrapper = [[[NSFileWrapper alloc] initWithURL:url options:0 error:&error] autorelease];
    if (dirWrapper == nil) {
        NSLog(@"Error creating directory wrapper: %@", error.localizedDescription);
        return nil;
    }   

    NSData *dirData = [dirWrapper serializedRepresentation];
    NSData *gzData = [dirData gzipDeflate];    
    return gzData;
}

According to this example: http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app you can get a NSData Object with the Zipped Data and then just write it with [data writeToFile....]

- (NSData *)exportToNSData {
    NSError *error;
    NSURL *url = [NSURL fileURLWithPath:_docPath];
    NSFileWrapper *dirWrapper = [[[NSFileWrapper alloc] initWithURL:url options:0 error:&error] autorelease];
    if (dirWrapper == nil) {
        NSLog(@"Error creating directory wrapper: %@", error.localizedDescription);
        return nil;
    }   

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