Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.git / Sources / XToolSupport / ProcessZIPCompressor.swift

ProcessZIPCompressor.swift36 lines · 1.0 KiBRaw
1import Foundation
2import XKit
3import Dependencies
4import PackLib
5import Subprocess
6import XUtils
7
8extension ZIPCompressor: DependencyKey {
9 // TODO: Use `powershell Compress-Archive` and `powershell Expand-Archive` on Windows
10
11 public static let liveValue = ZIPCompressor(
12 compress: { dir, progress in
13 progress(nil)
14
15 let dest = dir.deletingLastPathComponent().appendingPathComponent("app.ipa")
16
17 try await Subprocess.run(
18 .name("zip"),
19 arguments: ["-yqru0", dest.path, dir.lastPathComponent],
20 workingDirectory: FilePath(dir.deletingLastPathComponent()),
21 output: .discarded,
22 ).checkSuccess()
23
24 return dest
25 },
26 decompress: { ipa, directory, progress in
27 progress(nil)
28
29 try await Subprocess.run(
30 .name("unzip"),
31 arguments: ["-q", ipa.path, "-d", directory.path],
32 output: .discarded,
33 ).checkSuccess()
34 }
35 )
36}