From c0eba88aafa5fcfddc849b9b334de07c04223a59 Mon Sep 17 00:00:00 2001 From: Joel Milne Date: Sun, 27 Sep 2015 11:22:22 -0700 Subject: [PATCH 1/2] -removed unused variable fileSizeFraction (which causes issues being defined as CGFloat with no CoreGraphics includes) -fixed ReadMe issues. Example synchronous methods were wrong methods. All examples used wrong sharedInstance reference. --- Classes/NVHGzipFile.m | 2 -- README.md | 84 ++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/Classes/NVHGzipFile.m b/Classes/NVHGzipFile.m index 4830c35..ce99ec4 100644 --- a/Classes/NVHGzipFile.m +++ b/Classes/NVHGzipFile.m @@ -26,8 +26,6 @@ typedef NS_ENUM(NSInteger, NVHGzipFileErrorType) @interface NVHGzipFile () -@property (nonatomic,assign) CGFloat fileSizeFraction; - @end diff --git a/README.md b/README.md index cbb1bb2..d159cc8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Inflate Gzip file ```objective-c -[[NVHTarGzip shared] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) { +[[NVHTarGzip sharedInstance] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) { if (gzipError != nil) { NSLog(@"Error ungzipping %@", gzipError); } @@ -24,7 +24,7 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Untar file ```objective-c -[[NVHTarGzip shared] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) { +[[NVHTarGzip sharedInstance] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) { if (tarError != nil) { NSLog(@"Error untarring %@", tarError); } @@ -34,7 +34,7 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Inflate Gzip and Untar ```objective-c -[[NVHTarGzip shared] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) { +[[NVHTarGzip sharedInstance] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) { if (error != nil) { NSLog(@"Error extracting %@", error); } @@ -44,7 +44,7 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Deflate Gzip file ```objective-c -[[NVHTarGzip shared] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) { +[[NVHTarGzip sharedInstance] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) { if (gzipError != nil) { NSLog(@"Error gzipping %@", gzipError); } @@ -54,7 +54,7 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Tar file ```objective-c -[[NVHTarGzip shared] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) { +[[NVHTarGzip sharedInstance] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) { if (tarError != nil) { NSLog(@"Error tarring %@", tarError); } @@ -64,7 +64,7 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Deflate Gzip and Tar ```objective-c -[[NVHTarGzip shared] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) { +[[NVHTarGzip sharedInstance] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) { if (error != nil) { NSLog(@"Error packing %@", error); } @@ -77,61 +77,73 @@ The *tar* implementation is based on [Light-Untar-for-iOS](https://github.com/mh #### Inflate Gzip file ```objective-c -[[NVHTarGzip shared] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) { - if (gzipError != nil) { - NSLog(@"Error ungzipping %@", gzipError); - } -}]; +NSError *error; +BOOL success = [[NVHTarGzip sharedInstance] unGzipFileAtPath:sourcePath toPath:destinationPath error:&error]; +if (success) { + //continue +} else { + if (error) NSLog(@"Error ungzipping: %@", [error localizedDescription]); +} ``` #### Untar file ```objective-c -[[NVHTarGzip shared] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) { - if (tarError != nil) { - NSLog(@"Error untarring %@", tarError); - } -}]; +NSError *error; +BOOL success = [[NVHTarGzip sharedInstance] unTarFileAtPath:sourcePath toPath:destinationPath error:&error]; +if (success) { + //continue +} else { + if (error) NSLog(@"Error untarring: %@", [error localizedDescription]); +} ``` #### Inflate Gzip and Untar ```objective-c -[[NVHTarGzip shared] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) { - if (error != nil) { - NSLog(@"Error extracting %@", error); - } -}]; +NSError *error; +BOOL success = [[NVHTarGzip sharedInstance] unTarGzipFileAtPath:sourcePath toPath:destinationPath error:&error]; +if (success) { + //continue +} else { + if (error) NSLog(@"Error extracting: %@", [error localizedDescription]); +} ``` #### Deflate Gzip file ```objective-c -[[NVHTarGzip shared] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) { - if (gzipError != nil) { - NSLog(@"Error gzipping %@", gzipError); - } -}]; +NSError *error; +BOOL success = [[NVHTarGzip sharedInstance] gzipFileAtPath:sourcePath toPath:destinationPath error:&error]; +if (success) { + //continue +} else { + if (error) NSLog(@"Error gzipping: %@", [error localizedDescription]); +} ``` #### Tar file ```objective-c -[[NVHTarGzip shared] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) { - if (tarError != nil) { - NSLog(@"Error untarring %@", tarError); - } -}]; +NSError *error; +BOOL success = [[NVHTarGzip sharedInstance] tarFileAtPath:sourcePath toPath:destinationPath error:&error]; +if (success) { + //continue +} else { + if (error) NSLog(@"Error tarring: %@", [error localizedDescription]); +} ``` #### Deflate Gzip and Tar ```objective-c -[[NVHTarGzip shared] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) { - if (error != nil) { - NSLog(@"Error extracting %@", error); - } -}]; +NSError *error; +BOOL success = [[NVHTarGzip sharedInstance] tarGzipFileAtPath:sourcePath toPath:destinationPath error:&error]; +if (success) { + //continue +} else { + if (error) NSLog(@"Error extracting: %@", [error localizedDescription]); +} ``` ##### Note From cce77a7f96c756ff585e4d2530d6b077b05b8cd3 Mon Sep 17 00:00:00 2001 From: Joel Milne Date: Mon, 11 Apr 2016 19:30:20 -0700 Subject: [PATCH 2/2] Remove NSProgress for multithreading NSProgress crashes on multithreading when run in parallel. Not needed for our application so removed. --- Classes/NVHTarGzip.m | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Classes/NVHTarGzip.m b/Classes/NVHTarGzip.m index c8b6357..76f7f4a 100644 --- a/Classes/NVHTarGzip.m +++ b/Classes/NVHTarGzip.m @@ -45,14 +45,14 @@ - (BOOL)unTarGzipFileAtPath:(NSString *)sourcePath toPath:(NSString *)destinationPath error:(NSError **)error { NSString *temporaryPath = [self temporaryFilePathForPath:sourcePath]; - NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; - [progress becomeCurrentWithPendingUnitCount:1]; +// NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self unGzipFileAtPath:sourcePath toPath:temporaryPath error:error]; - [progress resignCurrent]; +// [progress resignCurrent]; if (*error != nil) { return NO; } - [progress becomeCurrentWithPendingUnitCount:1]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self unTarFileAtPath:temporaryPath toPath:destinationPath error:error]; NSError *removeTemporaryFileError = nil; [[NSFileManager defaultManager] removeItemAtPath:temporaryPath error:&removeTemporaryFileError]; @@ -63,7 +63,7 @@ - (BOOL)unTarGzipFileAtPath:(NSString *)sourcePath *error = removeTemporaryFileError; return NO; } - [progress resignCurrent]; +// [progress resignCurrent]; return YES; } @@ -85,14 +85,14 @@ - (BOOL)tarGzipFileAtPath:(NSString *)sourcePath toPath:(NSString *)destinationPath error:(NSError **)error { NSString *temporaryPath = [self temporaryFilePathForPath:sourcePath]; - NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; - [progress becomeCurrentWithPendingUnitCount:1]; +// NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self tarFileAtPath:sourcePath toPath:temporaryPath error:error]; - [progress resignCurrent]; +// [progress resignCurrent]; if (*error != nil) { return NO; } - [progress becomeCurrentWithPendingUnitCount:1]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self gzipFileAtPath:temporaryPath toPath:destinationPath error:error]; NSError* removeCacheError = nil; [[NSFileManager defaultManager] removeItemAtPath:temporaryPath error:&removeCacheError]; @@ -103,7 +103,7 @@ - (BOOL)tarGzipFileAtPath:(NSString *)sourcePath *error = removeCacheError; return NO; } - [progress resignCurrent]; +// [progress resignCurrent]; return YES; } @@ -125,19 +125,19 @@ - (void)unTarGzipFileAtPath:(NSString*)sourcePath toPath:(NSString*)destinationPath completion:(void(^)(NSError *))completion { NSString *temporaryPath = [self temporaryFilePathForPath:sourcePath]; - NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; - [progress becomeCurrentWithPendingUnitCount:1]; +// NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self unGzipFileAtPath:sourcePath toPath:temporaryPath completion:^(NSError *gzipError) { - [progress resignCurrent]; +// [progress resignCurrent]; if (gzipError != nil) { completion(gzipError); return; } - [progress becomeCurrentWithPendingUnitCount:1]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self unTarFileAtPath:temporaryPath toPath:destinationPath completion:^(NSError *tarError) { NSError* error = nil; [[NSFileManager defaultManager] removeItemAtPath:temporaryPath error:&error]; - [progress resignCurrent]; +// [progress resignCurrent]; if (tarError != nil) { error = tarError; } @@ -164,19 +164,19 @@ - (void)tarGzipFileAtPath:(NSString *)sourcePath toPath:(NSString *)destinationPath completion:(void(^)(NSError *))completion { NSString *temporaryPath = [self temporaryFilePathForPath:destinationPath]; - NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; - [progress becomeCurrentWithPendingUnitCount:1]; +// NSProgress *progress = [NSProgress progressWithTotalUnitCount:2]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self tarFileAtPath:sourcePath toPath:temporaryPath completion:^(NSError *tarError) { - [progress resignCurrent]; +// [progress resignCurrent]; if (tarError != nil) { completion(tarError); return; } - [progress becomeCurrentWithPendingUnitCount:1]; +// [progress becomeCurrentWithPendingUnitCount:1]; [self gzipFileAtPath:temporaryPath toPath:destinationPath completion:^(NSError *gzipError) { NSError *error = nil; [[NSFileManager defaultManager] removeItemAtPath:temporaryPath error:&error]; - [progress resignCurrent]; +// [progress resignCurrent]; if (gzipError != nil) { error = gzipError; }