5 // Created by Sam Soffes on 7/21/10.
6 // Copyright (c) Sam Soffes 2010-2015. All rights reserved.
9 #ifndef _SSZIPARCHIVE_H
10 #define _SSZIPARCHIVE_H
12 #import <Foundation/Foundation.h>
13 #include "SSZipCommon.h"
15 NS_ASSUME_NONNULL_BEGIN
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,
27 @protocol SSZipArchiveDelegate;
29 @interface SSZipArchive : NSObject
32 + (BOOL)isFilePasswordProtectedAtPath:(NSString *)path;
33 + (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * _Nullable * _Nullable)error NS_SWIFT_NOTHROW;
36 + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination;
37 + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(nullable id<SSZipArchiveDelegate>)delegate;
39 + (BOOL)unzipFileAtPath:(NSString *)path
40 toDestination:(NSString *)destination
41 overwrite:(BOOL)overwrite
42 password:(nullable NSString *)password
43 error:(NSError * *)error;
45 + (BOOL)unzipFileAtPath:(NSString *)path
46 toDestination:(NSString *)destination
47 overwrite:(BOOL)overwrite
48 password:(nullable NSString *)password
49 error:(NSError * *)error
50 delegate:(nullable id<SSZipArchiveDelegate>)delegate NS_REFINED_FOR_SWIFT;
52 + (BOOL)unzipFileAtPath:(NSString *)path
53 toDestination:(NSString *)destination
54 preserveAttributes:(BOOL)preserveAttributes
55 overwrite:(BOOL)overwrite
56 password:(nullable NSString *)password
57 error:(NSError * *)error
58 delegate:(nullable id<SSZipArchiveDelegate>)delegate;
60 + (BOOL)unzipFileAtPath:(NSString *)path
61 toDestination:(NSString *)destination
62 progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
63 completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
65 + (BOOL)unzipFileAtPath:(NSString *)path
66 toDestination:(NSString *)destination
67 overwrite:(BOOL)overwrite
68 password:(nullable NSString *)password
69 progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
70 completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
72 + (BOOL)unzipFileAtPath:(NSString *)path
73 toDestination:(NSString *)destination
74 preserveAttributes:(BOOL)preserveAttributes
75 overwrite:(BOOL)overwrite
76 nestedZipLevel:(NSInteger)nestedZipLevel
77 password:(nullable NSString *)password
78 error:(NSError **)error
79 delegate:(nullable id<SSZipArchiveDelegate>)delegate
80 progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
81 completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
84 // default compression level is Z_DEFAULT_COMPRESSION (from "zlib.h")
87 + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths;
88 + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;
90 + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory;
92 // with optional password, default encryption is AES
93 // don't use AES if you need compatibility with native macOS unzip and Archive Utility
94 + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password;
95 + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password;
96 + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password;
97 + (BOOL)createZipFileAtPath:(NSString *)path
98 withContentsOfDirectory:(NSString *)directoryPath
99 keepParentDirectory:(BOOL)keepParentDirectory
100 withPassword:(nullable NSString *)password
101 andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
102 + (BOOL)createZipFileAtPath:(NSString *)path
103 withContentsOfDirectory:(NSString *)directoryPath
104 keepParentDirectory:(BOOL)keepParentDirectory
105 compressionLevel:(int)compressionLevel
106 password:(nullable NSString *)password
108 progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
110 - (instancetype)init NS_UNAVAILABLE;
111 - (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
114 /// write empty folder
115 - (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password;
117 - (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password;
118 - (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password;
119 - (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes;
121 - (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password;
122 - (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes;
128 @protocol SSZipArchiveDelegate <NSObject>
132 - (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo;
133 - (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath;
135 - (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
136 - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
137 - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
138 - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath;
140 - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total;
144 NS_ASSUME_NONNULL_END
146 #endif /* _SSZIPARCHIVE_H */