Commit 7856c0f9 authored by Roy Marmelstein's avatar Roy Marmelstein

Merge branch 'tbergmen-master' into libraryincluded

parents f80c0038 958f359d
...@@ -28,6 +28,26 @@ public enum ZipError: Error { ...@@ -28,6 +28,26 @@ public enum ZipError: Error {
} }
} }
public enum ZipCompression: Int {
case NoCompression
case BestSpeed
case DefaultCompression
case BestCompression
internal var minizipCompression: Int32 {
switch self {
case .NoCompression:
return Z_NO_COMPRESSION
case .BestSpeed:
return Z_BEST_SPEED
case .DefaultCompression:
return Z_DEFAULT_COMPRESSION
case .BestCompression:
return Z_BEST_COMPRESSION
}
}
}
/// Zip class /// Zip class
public class Zip { public class Zip {
...@@ -197,19 +217,21 @@ public class Zip { ...@@ -197,19 +217,21 @@ public class Zip {
// MARK: Zip // MARK: Zip
/** /**
Zip files. Zip files.
- parameter paths: Array of NSURL filepaths. - parameter paths: Array of NSURL filepaths.
- parameter zipFilePath: Destination NSURL, should lead to a .zip filepath. - parameter zipFilePath: Destination NSURL, should lead to a .zip filepath.
- parameter password: Password string. Optional. - parameter password: Password string. Optional.
- parameter compression: Compression strategy
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1. - parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- throws: Error if zipping fails. - throws: Error if zipping fails.
- notes: Supports implicit progress composition - notes: Supports implicit progress composition
*/ */
public class func zipFiles(_ paths: [URL], zipFilePath: URL, password: String?, progress: ((_ progress: Double) -> ())?) throws { public class func zipFiles(paths: [URL], zipFilePath: URL, password: String?, compression: ZipCompression = .DefaultCompression, progress: ((_ progress: Double) -> ())?) throws {
// File manager // File manager
let fileManager = FileManager.default let fileManager = FileManager.default
...@@ -275,10 +297,10 @@ public class Zip { ...@@ -275,10 +297,10 @@ public class Zip {
catch {} catch {}
let buffer = malloc(chunkSize) let buffer = malloc(chunkSize)
if let password = password, let fileName = fileName { if let password = password, let fileName = fileName {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password, 0) zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password, 0)
} }
else if let fileName = fileName { else if let fileName = fileName {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0) zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0)
} }
else { else {
throw ZipError.zipFail throw ZipError.zipFail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment