Files
xtool-mirror/Sources/XToolSupport/ProcessZIPCompressor.swift
2025-05-12 16:33:57 +05:30

32 lines
1.0 KiB
Swift

import Foundation
import XKit
import Dependencies
import PackLib
extension ZIPCompressor: DependencyKey {
// TODO: Use `powershell Compress-Archive` and `powershell Expand-Archive` on Windows
public static let liveValue = ZIPCompressor(
compress: { dir, progress in
progress(nil)
let dest = dir.deletingLastPathComponent().appendingPathComponent("app.ipa")
let zip = Process()
zip.executableURL = try await ToolRegistry.locate("zip")
zip.currentDirectoryURL = dir.deletingLastPathComponent()
zip.arguments = ["-yqru0", dest.path, dir.lastPathComponent]
try await zip.runUntilExit()
return dest
},
decompress: { ipa, directory, progress in
progress(nil)
let unzip = Process()
unzip.executableURL = try await ToolRegistry.locate("unzip")
unzip.arguments = ["-q", ipa.path, "-d", directory.path]
try await unzip.runUntilExit()
}
)
}