SSZipArchive.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. SSZipArchiveErrorCodeFailedOpenFirstFile = -2,
  17. SSZipArchiveErrorCodeFileInfoNotLoadable = -3,
  18. SSZipArchiveErrorCodeFileContentNotReadable = -4,
  19. };
  20. @protocol SSZipArchiveDelegate;
  21. @interface SSZipArchive : NSObject
  22. // Password check
  23. + (BOOL)isFilePasswordProtectedAtPath:(NSString *)path;
  24. + (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * __nullable * __nullable)error NS_SWIFT_NOTHROW;
  25. // Unzip
  26. + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination;
  27. + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(nullable id<SSZipArchiveDelegate>)delegate;
  28. + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(nullable NSString *)password error:(NSError * *)error;
  29. + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(nullable NSString *)password error:(NSError * *)error delegate:(nullable id<SSZipArchiveDelegate>)delegate NS_REFINED_FOR_SWIFT;
  30. + (BOOL)unzipFileAtPath:(NSString *)path
  31. toDestination:(NSString *)destination
  32. preserveAttributes:(BOOL)preserveAttributes
  33. overwrite:(BOOL)overwrite
  34. password:(nullable NSString *)password
  35. error:(NSError * *)error
  36. delegate:(nullable id<SSZipArchiveDelegate>)delegate;
  37. + (BOOL)unzipFileAtPath:(NSString *)path
  38. toDestination:(NSString *)destination
  39. progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
  40. completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler;
  41. + (BOOL)unzipFileAtPath:(NSString *)path
  42. toDestination:(NSString *)destination
  43. overwrite:(BOOL)overwrite
  44. password:(nullable NSString *)password
  45. progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
  46. completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler;
  47. // Zip
  48. // without password
  49. + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths;
  50. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;
  51. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory;
  52. // with password, password could be nil
  53. + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(nullable NSString *)password;
  54. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password;
  55. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password;
  56. + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
  57. - (instancetype)initWithPath:(NSString *)path;
  58. @property (NS_NONATOMIC_IOSONLY, readonly) BOOL open;
  59. - (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password;
  60. - (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password;
  61. - (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password;
  62. - (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password;
  63. @property (NS_NONATOMIC_IOSONLY, readonly) BOOL close;
  64. @end
  65. @protocol SSZipArchiveDelegate <NSObject>
  66. @optional
  67. - (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo;
  68. - (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath;
  69. - (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
  70. - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
  71. - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
  72. - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath;
  73. - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total;
  74. - (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath;
  75. @end
  76. NS_ASSUME_NONNULL_END
  77. #endif /* _SSZIPARCHIVE_H */