SSZipArchive.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // SSZipArchive.h
  3. // SSZipArchive
  4. //
  5. // Created by Sam Soffes on 7/21/10.
  6. // Copyright (c) Sam Soffes 2010-2015. All rights reserved.
  7. //
  8. #ifndef _SSZIPARCHIVE_H
  9. #define _SSZIPARCHIVE_H
  10. #import <Foundation/Foundation.h>
  11. #include "SSZipCommon.h"
  12. NS_ASSUME_NONNULL_BEGIN
  13. extern NSString *const SSZipArchiveErrorDomain;
  14. typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
  15. SSZipArchiveErrorCodeFailedOpenZipFile = -1,
  16. SSZipArchiveErrorCodeFailedOpenFileInZip = -2,
  17. SSZipArchiveErrorCodeFileInfoNotLoadable = -3,
  18. SSZipArchiveErrorCodeFileContentNotReadable = -4,
  19. SSZipArchiveErrorCodeFailedToWriteFile = -5,
  20. SSZipArchiveErrorCodeInvalidArguments = -6,
  21. };
  22. @protocol SSZipArchiveDelegate;
  23. @interface SSZipArchive : NSObject
  24. // Password check
  25. + (BOOL)isFilePasswordProtectedAtPath:(NSString *)path;
  26. + (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * _Nullable * _Nullable)error NS_SWIFT_NOTHROW;
  27. // Unzip
  28. + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination;
  29. + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(nullable id<SSZipArchiveDelegate>)delegate;
  30. + (BOOL)unzipFileAtPath:(NSString *)path
  31. toDestination:(NSString *)destination
  32. overwrite:(BOOL)overwrite
  33. password:(nullable NSString *)password
  34. error:(NSError * *)error;
  35. + (BOOL)unzipFileAtPath:(NSString *)path
  36. toDestination:(NSString *)destination
  37. overwrite:(BOOL)overwrite
  38. password:(nullable NSString *)password
  39. error:(NSError * *)error
  40. delegate:(nullable id<SSZipArchiveDelegate>)delegate NS_REFINED_FOR_SWIFT;
  41. + (BOOL)unzipFileAtPath:(NSString *)path
  42. toDestination:(NSString *)destination
  43. preserveAttributes:(BOOL)preserveAttributes
  44. overwrite:(BOOL)overwrite
  45. password:(nullable NSString *)password
  46. error:(NSError * *)error
  47. delegate:(nullable id<SSZipArchiveDelegate>)delegate;
  48. + (BOOL)unzipFileAtPath:(NSString *)path
  49. toDestination:(NSString *)destination
  50. progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
  51. completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
  52. + (BOOL)unzipFileAtPath:(NSString *)path
  53. toDestination:(NSString *)destination
  54. overwrite:(BOOL)overwrite
  55. password:(nullable NSString *)password
  56. progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
  57. completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
  58. // Zip
  59. // without password
  60. + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths;
  61. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;
  62. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory;
  63. // with password, password could be nil
  64. + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password;
  65. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password;
  66. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password;
  67. + (BOOL)createZipFileAtPath:(NSString *)path
  68. withContentsOfDirectory:(NSString *)directoryPath
  69. keepParentDirectory:(BOOL)keepParentDirectory
  70. withPassword:(nullable NSString *)password
  71. andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
  72. - (instancetype)init NS_UNAVAILABLE;
  73. - (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
  74. - (BOOL)open;
  75. - (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password;
  76. - (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password;
  77. - (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password;
  78. - (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password;
  79. - (BOOL)close;
  80. @end
  81. @protocol SSZipArchiveDelegate <NSObject>
  82. @optional
  83. - (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo;
  84. - (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath;
  85. - (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
  86. - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
  87. - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
  88. - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath;
  89. - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total;
  90. - (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath;
  91. @end
  92. NS_ASSUME_NONNULL_END
  93. #endif /* _SSZIPARCHIVE_H */