|
3 | 3 | // SSZipArchive
|
4 | 4 | //
|
5 | 5 | // Created by Sam Soffes on 7/21/10.
|
6 |
| -// Copyright (c) Sam Soffes 2010-2015. All rights reserved. |
7 | 6 | //
|
8 | 7 |
|
9 | 8 | #ifndef _SSZIPARCHIVE_H
|
10 | 9 | #define _SSZIPARCHIVE_H
|
11 | 10 |
|
12 | 11 | #import <Foundation/Foundation.h>
|
13 |
| -#include "Common.h" |
| 12 | + |
| 13 | +#import "SSZipCommon.h" |
| 14 | + |
| 15 | +NS_ASSUME_NONNULL_BEGIN |
| 16 | + |
| 17 | +extern NSString *const SSZipArchiveErrorDomain; |
| 18 | +typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) { |
| 19 | + SSZipArchiveErrorCodeFailedOpenZipFile = -1, |
| 20 | + SSZipArchiveErrorCodeFailedOpenFileInZip = -2, |
| 21 | + SSZipArchiveErrorCodeFileInfoNotLoadable = -3, |
| 22 | + SSZipArchiveErrorCodeFileContentNotReadable = -4, |
| 23 | + SSZipArchiveErrorCodeFailedToWriteFile = -5, |
| 24 | + SSZipArchiveErrorCodeInvalidArguments = -6, |
| 25 | + SSZipArchiveErrorCodeSymlinkEscapesTargetDirectory = -7, |
| 26 | +}; |
14 | 27 |
|
15 | 28 | @protocol SSZipArchiveDelegate;
|
16 | 29 |
|
17 | 30 | @interface SSZipArchive : NSObject
|
18 | 31 |
|
| 32 | +// Password check |
| 33 | ++ (BOOL)isFilePasswordProtectedAtPath:(NSString *)path; |
| 34 | ++ (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * _Nullable * _Nullable)error NS_SWIFT_NOTHROW; |
| 35 | + |
| 36 | +// Total payload size |
| 37 | ++ (NSNumber *)payloadSizeForArchiveAtPath:(NSString *)path error:(NSError **)error; |
| 38 | + |
19 | 39 | // Unzip
|
20 | 40 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination;
|
21 |
| -+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id<SSZipArchiveDelegate>)delegate; |
| 41 | ++ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(nullable id<SSZipArchiveDelegate>)delegate; |
| 42 | + |
| 43 | ++ (BOOL)unzipFileAtPath:(NSString *)path |
| 44 | + toDestination:(NSString *)destination |
| 45 | + overwrite:(BOOL)overwrite |
| 46 | + password:(nullable NSString *)password |
| 47 | + error:(NSError * *)error; |
| 48 | + |
| 49 | ++ (BOOL)unzipFileAtPath:(NSString *)path |
| 50 | + toDestination:(NSString *)destination |
| 51 | + overwrite:(BOOL)overwrite |
| 52 | + password:(nullable NSString *)password |
| 53 | + error:(NSError * *)error |
| 54 | + delegate:(nullable id<SSZipArchiveDelegate>)delegate NS_REFINED_FOR_SWIFT; |
| 55 | + |
| 56 | ++ (BOOL)unzipFileAtPath:(NSString *)path |
| 57 | + toDestination:(NSString *)destination |
| 58 | + preserveAttributes:(BOOL)preserveAttributes |
| 59 | + overwrite:(BOOL)overwrite |
| 60 | + password:(nullable NSString *)password |
| 61 | + error:(NSError * *)error |
| 62 | + delegate:(nullable id<SSZipArchiveDelegate>)delegate; |
| 63 | + |
| 64 | ++ (BOOL)unzipFileAtPath:(NSString *)path |
| 65 | + toDestination:(NSString *)destination |
| 66 | + progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler |
| 67 | + completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; |
22 | 68 |
|
23 |
| -+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError * *)error; |
24 |
| -+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError * *)error delegate:(id<SSZipArchiveDelegate>)delegate; |
| 69 | ++ (BOOL)unzipFileAtPath:(NSString *)path |
| 70 | + toDestination:(NSString *)destination |
| 71 | + overwrite:(BOOL)overwrite |
| 72 | + password:(nullable NSString *)password |
| 73 | + progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler |
| 74 | + completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; |
25 | 75 |
|
26 | 76 | + (BOOL)unzipFileAtPath:(NSString *)path
|
27 |
| - toDestination:(NSString *)destination |
28 |
| - progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler |
29 |
| - completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler; |
| 77 | + toDestination:(NSString *)destination |
| 78 | + preserveAttributes:(BOOL)preserveAttributes |
| 79 | + overwrite:(BOOL)overwrite |
| 80 | + nestedZipLevel:(NSInteger)nestedZipLevel |
| 81 | + password:(nullable NSString *)password |
| 82 | + error:(NSError **)error |
| 83 | + delegate:(nullable id<SSZipArchiveDelegate>)delegate |
| 84 | + progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler |
| 85 | + completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; |
30 | 86 |
|
31 | 87 | + (BOOL)unzipFileAtPath:(NSString *)path
|
32 |
| - toDestination:(NSString *)destination |
33 |
| - overwrite:(BOOL)overwrite |
34 |
| - password:(NSString *)password |
35 |
| - progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler |
36 |
| - completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler; |
| 88 | + toDestination:(NSString *)destination |
| 89 | + preserveAttributes:(BOOL)preserveAttributes |
| 90 | + overwrite:(BOOL)overwrite |
| 91 | + symlinksValidWithin:(nullable NSString *)symlinksValidWithin |
| 92 | + nestedZipLevel:(NSInteger)nestedZipLevel |
| 93 | + password:(nullable NSString *)password |
| 94 | + error:(NSError **)error |
| 95 | + delegate:(nullable id<SSZipArchiveDelegate>)delegate |
| 96 | + progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler |
| 97 | + completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; |
37 | 98 |
|
38 | 99 | // Zip
|
| 100 | +// default compression level is Z_DEFAULT_COMPRESSION (from "zlib.h") |
| 101 | +// keepParentDirectory: if YES, then unzipping will give `directoryName/fileName`. If NO, then unzipping will just give `fileName`. Default is NO. |
39 | 102 |
|
40 | 103 | // without password
|
41 |
| -+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths; |
| 104 | ++ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths; |
42 | 105 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;
|
43 |
| -+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirector; |
44 | 106 |
|
45 |
| -// with password, password could be nil |
46 |
| -+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(NSString *)password; |
47 |
| -+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(NSString *)password; |
48 |
| -+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(NSString *)password; |
49 |
| - |
50 |
| -- (instancetype)initWithPath:(NSString *)path; |
51 |
| -@property (NS_NONATOMIC_IOSONLY, readonly, getter = isOpen) BOOL open; |
52 |
| -- (BOOL)writeFile:(NSString *)path withPassword:(NSString *)password; |
53 |
| -- (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName withPassword:(NSString *)password; |
54 |
| -- (BOOL)writeData:(NSData *)data filename:(NSString *)filename withPassword:(NSString *)password; |
55 |
| -@property (NS_NONATOMIC_IOSONLY, readonly, getter = isClosed) BOOL close; |
| 107 | ++ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory; |
| 108 | + |
| 109 | +// with optional password, default encryption is AES |
| 110 | +// don't use AES if you need compatibility with native macOS unzip and Archive Utility |
| 111 | ++ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password; |
| 112 | ++ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler; |
| 113 | ++ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password; |
| 114 | ++ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password; |
| 115 | ++ (BOOL)createZipFileAtPath:(NSString *)path |
| 116 | + withContentsOfDirectory:(NSString *)directoryPath |
| 117 | + keepParentDirectory:(BOOL)keepParentDirectory |
| 118 | + withPassword:(nullable NSString *)password |
| 119 | + andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler; |
| 120 | ++ (BOOL)createZipFileAtPath:(NSString *)path |
| 121 | + withContentsOfDirectory:(NSString *)directoryPath |
| 122 | + keepParentDirectory:(BOOL)keepParentDirectory |
| 123 | + compressionLevel:(int)compressionLevel |
| 124 | + password:(nullable NSString *)password |
| 125 | + AES:(BOOL)aes |
| 126 | + progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler; |
| 127 | +//suport symlink compress --file |
| 128 | ++ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password keepSymlinks:(BOOL)keeplinks; |
| 129 | +//suport symlink compress --directory |
| 130 | ++ (BOOL)createZipFileAtPath:(NSString *)path |
| 131 | + withContentsOfDirectory:(NSString *)directoryPath |
| 132 | + keepParentDirectory:(BOOL)keepParentDirectory |
| 133 | + compressionLevel:(int)compressionLevel |
| 134 | + password:(nullable NSString *)password |
| 135 | + AES:(BOOL)aes |
| 136 | + progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler |
| 137 | + keepSymlinks:(BOOL)keeplinks; |
| 138 | + |
| 139 | +- (instancetype)init NS_UNAVAILABLE; |
| 140 | +- (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER; |
| 141 | +- (BOOL)open; |
| 142 | +- (BOOL)openForAppending; |
| 143 | + |
| 144 | +/// write empty folder |
| 145 | +- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password; |
| 146 | +/// write file |
| 147 | +- (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password; |
| 148 | +- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password; |
| 149 | +- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes; |
| 150 | +///write symlink files |
| 151 | +- (BOOL)writeSymlinkFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes; |
| 152 | +/// write data |
| 153 | +- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password; |
| 154 | +- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes; |
| 155 | + |
| 156 | +- (BOOL)close; |
56 | 157 |
|
57 | 158 | @end
|
58 | 159 |
|
|
69 | 170 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath;
|
70 | 171 |
|
71 | 172 | - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total;
|
72 |
| -- (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath; |
73 | 173 |
|
74 | 174 | @end
|
75 | 175 |
|
| 176 | +NS_ASSUME_NONNULL_END |
| 177 | + |
76 | 178 | #endif /* _SSZIPARCHIVE_H */
|
0 commit comments