go-apkutils is a library written in go for parsing and extracting content from APKs.
go-apkutils provides a few interfaces for handling alpine APK packages and APKINDEX files.
There is a highlevel Apk
and ApkIndex
struct that provides access to package and index information.
See Examples for some example code.
f, err := os.Open("curl-7.83.1-r1.apk")
if err != nil {
panic(err)
}
apk, err := apk.ReadApk(f)
if err != nil {
panic(err)
}
fmt.Println(apk)
f, err := os.Open("APKINDEX")
if err != nil {
panic(err)
}
index, err := index.ReadApkIndex(f)
if err != nil {
panic(err)
}
fmt.Println(index.Entries)
// List of apk names
apkFile := []string{
"curl-7.83.1-r1.apk",
"gvim-8.2.5000-r0.apk",
"strace-5.17-r0.apk",
}
// Create APKINDEX file
f, err := os.OpenFile("APKINDEX.test", os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
log.Fatalln("Error opening APKINDEX file:", err)
}
// Create a writer
w := index.NewWriter(f)
defer w.Close()
for _, filePath := range apkFile {
f, err := os.Open(filePath)
if err != nil {
log.Fatalln("Error opening file:", err)
}
apkFile, err := apk.ReadApk(f)
if err != nil {
log.Fatalln("Error reading apk file:", err)
}
w.WriteApk(apkFile)
}
w.Close()