NVHTarGzip 1.0.1

NVHTarGzip 1.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年7月

Niels van Hoorn维护。



  • Niels van Hoorn

这是一个直接操作文件的ObjC库,用于打包/解包以及压缩/解压缩。它不是一个在NSData上的分类实现(与GZIPGodzippa不同),所以不需要首先将整个文件加载到内存中。

名为tar的实现基于Light-Untar-for-iOS,但扩展了通过NSProgress进行进度报告的功能。

使用

异步

解压Gzip文件

[[NVHTarGzip shared] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error ungzipping %@", gzipError);
    }
}];

解压tar文件

[[NVHTarGzip shared] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error untarring %@", tarError);
    }
}];

解压Gzip并解压tar

[[NVHTarGzip shared] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error extracting %@", error);
    }
}];

压缩Gzip文件

[[NVHTarGzip shared] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error gzipping %@", gzipError);
    }
}];

打包tar文件

[[NVHTarGzip shared] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error tarring %@", tarError);
    }
}];

压缩Gzip并打包tar

[[NVHTarGzip shared] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error packing %@", error);
    }
}];

同步

解压Gzip文件

[[NVHTarGzip shared] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error ungzipping %@", gzipError);
    }
}];

解压tar文件

[[NVHTarGzip shared] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error untarring %@", tarError);
    }
}];

解压Gzip并解压tar

[[NVHTarGzip shared] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error extracting %@", error);
    }
}];

压缩Gzip文件

[[NVHTarGzip shared] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error gzipping %@", gzipError);
    }
}];

打包tar文件

[[NVHTarGzip shared] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error untarring %@", tarError);
    }
}];

压缩Gzip并打包tar

[[NVHTarGzip shared] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error extracting %@", error);
    }
}];
注意

连续的tar.gz打包和解包将将中间的tar文件tarungzip到临时目录中,随后/gzipuntar它。在gzip/untar后,将删除临时文件。您可以通过在提取前设置单例对象来自定义cachePath。

[[NVHTarGzip shared] setCachePath:customCachePath];

进度

NVHTarGzip 使用 NSProgress 来处理进度报告。为了跟踪进度,请创建自己的进度实例并使用 KVO 来检查 fractionCompleted 属性。请参阅 NSProgress 的文档 和 Ole Begemann 的这篇出色的文章 这篇优秀的文章 以获取更多信息。

NSProgress* progress = [NSProgress progressWithTotalUnitCount:1];
NSString* keyPath = NSStringFromSelector(@selector(fractionCompleted));
[progress addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionInitial context:NVHProgressFractionCompletedObserverContext];
[progress becomeCurrentWithPendingUnitCount:1];
[[NVHTarGzip shared] unTarGzipFileAtPath:self.demoSourceFilePath toPath:self.demoDestinationFilePath completion:^(NSError* error) {
    [progress resignCurrent];
    [progress removeObserver:self forKeyPath:keyPath];
}];

在示例项目中查看完整的用法示例;首先克隆仓库,然后从 Example 目录运行 pod install

待办事项

添加流支持(《NSStream》)。这将允许在打包和解包 tar.gz 时使用中间文件,从而加快速度。

欢迎提交拉取请求!

安装

NVHTarGzip 可通过 CocoaPods 获取,安装它只需将以下行添加到您的 Podfile 文件中

pod "NVHTarGzip"

作者

Niels van Hoorn, [email protected]

许可证

NVHTarGzipMIT 许可 下可用。有关更多信息,请参阅 LICENSE 文件。