This is ObjC wrapper around tar and gzip that directly manipulates files and isn't implemented as a category on NSData like GZIP and Godzippa, so the full file doesn't have to be loaded into memory.
The tar implementation is based on Light-Untar-for-iOS, but is extended to include progress reporting through NSProgress
[[NVHTarGzip shared] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
if (gzipError != nil) {
NSLog(@"Error unzipping %@",gzipError);
}
}];
[[NVHTarGzip shared] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
if (tarError != nil) {
NSLog(@"Error untarring %@",tarError);
}
}];
[[NVHTarGzip shared] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
if (error != nil) {
NSLog(@"Error extracting %@",error);
}
}];
This will unzip the file to a cache-directory, and consequently extract the tar archive. After untarring, the cache-file is deleted. You can customize the cachePath by setting it on the singleton object before extracting:
[[NVHTarGzip shared] setCachePath:customCachePath];
NVHTarGzip
uses NSProgress
to handle progress reporting. To keep track of progress create your own progress instance and use KVO to inspect the fractionCompleted
property. See the documentation of NSProgress and this great article by Ole Begemann for more information.
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];
}];
Checkout a full usage example in the example project; clone the repo, and run pod install
from the Example directory first.
Compressing files is currently not supported. Pull requests are welcome!
NVHTarGzip is available through CocoaPods, to install it simply add the following line to your Podfile:
pod "NVHTarGzip"
Niels van Hoorn, [email protected]
NVHTarGzip is available under the MIT license. See the LICENSE file for more info.