Initial implementation of APKINDEX, fetching, reading, parsing, & merging

This commit is contained in:
2024-11-08 21:22:33 +11:00
parent f6cbddb608
commit 941dfae317
18 changed files with 877 additions and 65 deletions

View File

@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
struct ApkIndex {
let packages: [ApkIndexPackage]
}
extension ApkIndex {
func first(name: String) -> ApkIndexPackage? {
self.packages.first {
$0.name == name
}
}
}
extension ApkIndex {
static func merge<S: Sequence>(_ tables: S) -> Self where S.Element == Self {
Self.init(packages: tables.flatMap(\.packages))
}
static func merge(_ tables: Self...) -> ApkIndex {
Self.init(packages: tables.flatMap(\.packages))
}
}
extension ApkIndex {
init(raw: ApkRawIndex) throws {
self.packages = try raw.packages.map {
try ApkIndexPackage(raw: $0)
}
}
}