mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 21:41:31 +00:00
Initial implementation of APKINDEX, fetching, reading, parsing, & merging
This commit is contained in:
31
Sources/apk/Index/ApkIndex.swift
Normal file
31
Sources/apk/Index/ApkIndex.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user