【问题标题】:How to zip, unzip files in Objective C (arm64 support)如何在 Objective C 中压缩、解压缩文件(arm64 支持)
【发布时间】:2014-01-07 17:02:29
【问题描述】:

我正在寻找一种在支持 arm64 的 ios 上压缩和解压缩文件的方法。我在看 Github,但没有一个支持 arm64。是否已经有用于压缩和解压缩文件的现成库。 (如果您知道如何集成 7zip、bzip2、gzip、rar 的方法,我会很高兴的)

我现在正在使用 SSZipArchive,但它不起作用:

#import "SSZipArchive.h"

NSArray *nameWithoutExtention = [[[[self files] objectAtIndex:indexPath.row] lastPathComponent] componentsSeparatedByString:@"."];
NSString *fileName = [nameWithoutExtention objectAtIndex:0];
NSString *destPath = [NSString stringWithFormat:@"%@/%@", self.directory, fileName];
[fileManager createDirectoryAtPath:destPath withIntermediateDirectories:YES attributes:nil error:nil];
[SSZipArchive unzipFileAtPath:[[self files] objectAtIndex:indexPath.row] toDestination:destPath];

【问题讨论】:

  • 这有什么关系?如果它们是开源的,您可以自己编译为 64 位。
  • 但是当我添加 github.com/dive/ALZipArchive 时,我收到很多错误消息,我无法修复,所以我认为必须已经有一个固定的项目/库
  • 我使用 GTMNSData+zlib。它是为我所要求的一切而编译的。
  • 有哪些错误?
  • 你为什么不使用 zlib 并且你可以制作静态库,或者只是将所有 .c 文件也添加到你的项目中

标签: ios objective-c zip unzip bzip2


【解决方案1】:

您可以查看official SSZipArchive Objective-C example(适用于纯arm64的iOS11)。

压缩包:

NSString *sampleDataPath = [[NSBundle mainBundle].bundleURL
                            URLByAppendingPathComponent:@"Sample Data"
                            isDirectory:YES].path;
NSString *zipPath = [self tempZipPath];
BOOL success = [SSZipArchive createZipFileAtPath:zipPath
                         withContentsOfDirectory:sampleDataPath];

解压:

NSString *unzipPath = [self tempUnzipPath];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath
                               toDestination:unzipPath];

tempZipPathtempUnzipPath 被声明为:

- (NSString *)tempZipPath {
  NSString *path = [NSString stringWithFormat:@"%@/\%@.zip",
                    NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
                    [NSUUID UUID].UUIDString];
  return path;
}

- (NSString *)tempUnzipPath {
  NSString *path = [NSString stringWithFormat:@"%@/\%@",
                    NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
                    [NSUUID UUID].UUIDString];
  NSURL *url = [NSURL fileURLWithPath:path];
  NSError *error = nil;
  [[NSFileManager defaultManager] createDirectoryAtURL:url
                           withIntermediateDirectories:YES
                                            attributes:nil
                                                 error:&error];
  if (error) {
    return nil;
  }
  return url.path;
}

【讨论】:

    猜你喜欢
    • 2012-06-30
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    相关资源
    最近更新 更多