diff --git a/Sources/LibzipSwift/ZipArchive.swift b/Sources/LibzipSwift/ZipArchive.swift index 4366610..f09fec0 100644 --- a/Sources/LibzipSwift/ZipArchive.swift +++ b/Sources/LibzipSwift/ZipArchive.swift @@ -10,6 +10,8 @@ import libzip public final class ZipArchive: ZipErrorHandler { private var compressionCallback: ((Double) -> Void)? + private var compressionMethod: CompressionMethod = .default + private var compressionLevel: CompressionLevel = .fastest internal var archivePointer: OpaquePointer! @@ -305,6 +307,7 @@ public final class ZipArchive: ZipErrorHandler { var external_fa = entry.externalAttributes.attributes external_fa |= permissionsMask try entry.setExternalAttributes(operatingSystem: .unix, attributes: external_fa) + try entry.setCompression(method: compressionMethod, flags: compressionLevel) } } return result @@ -353,6 +356,11 @@ public final class ZipArchive: ZipErrorHandler { return false } + public func setCompression(cm: CompressionMethod, cl: CompressionLevel) { + compressionMethod = cm + compressionLevel = cl + } + /// extract all entries to folder. /// - Parameters: /// - dir: the dst folder. diff --git a/Sources/LibzipSwift/ZipConst.swift b/Sources/LibzipSwift/ZipConst.swift index 22771ad..32eacc8 100644 --- a/Sources/LibzipSwift/ZipConst.swift +++ b/Sources/LibzipSwift/ZipConst.swift @@ -25,6 +25,7 @@ public struct CompressionMethod: RawRepresentable { public static let `default` = CompressionMethod(rawValue: ZIP_CM_DEFAULT) public static let store = CompressionMethod(rawValue: ZIP_CM_STORE) + public static let bzip2 = CompressionMethod(rawValue: ZIP_CM_BZIP2) public static let deflate = CompressionMethod(rawValue: ZIP_CM_DEFLATE) public static let deflate64 = CompressionMethod(rawValue: ZIP_CM_DEFLATE64) }