From 0c98af7f9ec73ae045492c10896ce433defd96cd Mon Sep 17 00:00:00 2001 From: David Evans Date: Sat, 21 Jan 2017 01:05:45 +0000 Subject: [PATCH 1/2] Added support for retrieving zip progress information. No additional information required. --- SSZipArchive/SSZipArchive.h | 1 + SSZipArchive/SSZipArchive.m | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SSZipArchive/SSZipArchive.h b/SSZipArchive/SSZipArchive.h index 3931bc4..c4b68b4 100755 --- a/SSZipArchive/SSZipArchive.h +++ b/SSZipArchive/SSZipArchive.h @@ -60,6 +60,7 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(nullable NSString *)password; + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password; + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password; ++ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler; - (instancetype)initWithPath:(NSString *)path; @property (NS_NONATOMIC_IOSONLY, readonly) BOOL open; diff --git a/SSZipArchive/SSZipArchive.m b/SSZipArchive/SSZipArchive.m index 1b9d073..71cd042 100755 --- a/SSZipArchive/SSZipArchive.m +++ b/SSZipArchive/SSZipArchive.m @@ -519,6 +519,15 @@ + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password{ + return [self createZipFileAtPath:password + withContentsOfDirectory:directoryPath + keepParentDirectory:keepParentDirectory + withPassword:password + andProgressHandler:nil + ]; +} + ++ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler { BOOL success = NO; NSFileManager *fileManager = nil; @@ -813,4 +822,4 @@ return date; } -@end \ No newline at end of file +@end From 97cd6424fd950b225fed3402499824d2a382a722 Mon Sep 17 00:00:00 2001 From: David Evans Date: Sat, 21 Jan 2017 18:29:28 +0000 Subject: [PATCH 2/2] Added changes left out in last commit. Users can now provide a callback to retrieve real-time statistics on the progress of zipping files. --- SSZipArchive/SSZipArchive.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SSZipArchive/SSZipArchive.m b/SSZipArchive/SSZipArchive.m index 71cd042..456fbbd 100755 --- a/SSZipArchive/SSZipArchive.m +++ b/SSZipArchive/SSZipArchive.m @@ -537,8 +537,10 @@ // use a local filemanager (queue/thread compatibility) fileManager = [[NSFileManager alloc] init]; NSDirectoryEnumerator *dirEnumerator = [fileManager enumeratorAtPath:directoryPath]; + NSArray *allObjects = dirEnumerator.allObjects; + NSUInteger total = allObjects.count, complete = 0; NSString *fileName; - while ((fileName = [dirEnumerator nextObject])) { + for (fileName in allObjects) { BOOL isDir; NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:fileName]; [fileManager fileExistsAtPath:fullFilePath isDirectory:&isDir]; @@ -560,6 +562,10 @@ [zipArchive writeFileAtPath:tempFilePath withFileName:tempFileFilename withPassword:password]; } } + complete++; + if (progressHandler) { + progressHandler(complete, total); + } } success = [zipArchive close]; }