Merge pull request #129 from Binauric/master

Add support for archives in folders
This commit is contained in:
Douglas Bumby
2015-04-06 13:22:46 -04:00
2 changed files with 37 additions and 1 deletions
+8
View File
@@ -25,12 +25,20 @@
// Zip
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames;
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames inFolder:(NSString*)folder;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath inFolder:(NSString*)folder;
- (id)initWithPath:(NSString *)path;
- (BOOL)open;
- (BOOL)writeFile:(NSString *)path;
- (BOOL)writeData:(NSData *)data filename:(NSString *)filename;
// supports writing files with logical folder/directory structure
// *path* is the absolute path of the file that will be compressed
// *fileName* is the relative name of the file how it is stored within the zip e.g. /folder/subfolder/text1.txt
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName;
- (BOOL)close;
@end
+29 -1
View File
@@ -320,8 +320,30 @@
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths inFolder:(NSString *)folder {
BOOL success = NO;
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
if ([zipArchive open]) {
for (NSString *path in paths) {
if (!folder) {
[zipArchive writeFile:path];
}
else {
NSString *destination = [folder stringByAppendingPathComponent:path.lastPathComponent];
[zipArchive writeFileAtPath:path withFileName:destination];
}
}
success = [zipArchive close];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
#if !__has_feature(objc_arc)
[zipArchive release];
#endif
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath inFolder:(NSString *)folder {
BOOL success = NO;
NSFileManager *fileManager = nil;
@@ -336,6 +358,9 @@
while ((fileName = [dirEnumerator nextObject])) {
BOOL isDir;
NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:fileName];
if (folder) {
fileName = [folder stringByAppendingPathComponent: fileName];
}
[fileManager fileExistsAtPath:fullFilePath isDirectory:&isDir];
if (!isDir) {
[zipArchive writeFileAtPath:fullFilePath withFileName:fileName];
@@ -352,6 +377,9 @@
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath inFolder:nil];
}
- (id)initWithPath:(NSString *)path {
if ((self = [super init])) {