Support for splitting archive

This commit is contained in:
Jean-Baptiste
2017-11-21 18:13:05 +01:00
committed by GitHub
parent 82af68a7d5
commit 150f9a276e

View File

@@ -657,7 +657,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(NSString *)password
{
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
BOOL success = [zipArchive open];
BOOL success = [zipArchive openWithSplitSize:0];
if (success) {
for (NSString *filePath in paths) {
success &= [zipArchive writeFile:filePath withPassword:password];
@@ -686,7 +686,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
keepParentDirectory:(BOOL)keepParentDirectory
withPassword:(nullable NSString *)password
andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirectory compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:YES progressHandler:progressHandler];
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirectory compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:YES diskSize:0 progressHandler:progressHandler];
}
+ (BOOL)createZipFileAtPath:(NSString *)path
@@ -695,10 +695,11 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
compressionLevel:(int)compressionLevel
password:(nullable NSString *)password
AES:(BOOL)aes
diskSize:(int)diskSize
progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
BOOL success = [zipArchive open];
BOOL success = [zipArchive openWithSplitSize:diskSize];
if (success) {
// use a local fileManager (queue/thread compatibility)
NSFileManager *fileManager = [[NSFileManager alloc] init];
@@ -748,11 +749,13 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return self;
}
- (BOOL)open
- (BOOL)openWithSplitSize:(int)disk_size
{
NSAssert((_zip == NULL), @"Attempting to open an archive which is already open");
_zip = zipOpen(_path.fileSystemRepresentation, APPEND_STATUS_CREATE);
if (disk_size < 1024) //avoid creating split of size < 1 KB
_zip = zipOpen(_path.fileSystemRepresentation, APPEND_STATUS_CREATE);
else
_zip = zipOpen3(_path.fileSystemRepresentation, APPEND_STATUS_CREATE, disk_size, NULL, NULL);
return (NULL != _zip);
}