apkutils

package module
v0.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 7 Imported by: 0

README

Go alpine APK Utils

go-apkutils is a library written in go for parsing and extracting content from APKs.

Overview

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.

1. Extract metadata from an apk package file

	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)

2. Read apk index files

	f, err := os.Open("APKINDEX")
	if err != nil {
		panic(err)
	}
	index, err := index.ReadApkIndex(f)
	if err != nil {
		panic(err)
	}
	fmt.Println(index.Entries)

3. Write apk index files

    // 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()

Documentation

Index

Constants

View Source
const (
	GzipID1     = 0x1f
	GzipID2     = 0x8b
	GzipDeflate = 8
)

Signature bytes for finding GZIP header

Variables

This section is empty.

Functions

func ReadGzipHeader added in v0.1.4

func ReadGzipHeader(buf []byte) bool

ReadGzipHeader reads the header of a gzip file if found.

func TarGzip added in v0.2.0

func TarGzip(filename string, b []byte, writeEOFTar bool) (int, []byte, error)

TarGzip create a tar.gz file data from some source bytes. Optionally, you can specify not to write an EnfOfTar header. This function can be used to create signature.tar.gz files for signed APKINDEX files, and APKINDEX.unsigned.tar.gz of an APKINDEX file.

Types

type ApkFile

type ApkFile struct {
	PullChecksum string
	PkgInfo      *PkgInfo
	PkgFileSize  int
}

ApkFile is an APK file information with the derived PullChecksum.

func (*ApkFile) ToIndexEntry

func (apkFile *ApkFile) ToIndexEntry() string

ToIndexEntry converts an ApkPkg (Package) to an index record in APKINDEX.

type ApkIndex

type ApkIndex struct {
	Entries []*IndexEntry
}

ApkIndex is a list of IndexEntries of an APKINDEX file.

type IndexEntry

type IndexEntry struct {
	PullChecksum         string
	PackageName          string
	PackageVersion       string
	PackageArchitecture  string
	PackageSize          string
	PackageInstalledSize string
	PackageDescription   string
	PackageUrl           string
	PackageLicense       string
	PackageOrigin        string
	PackageMaintainer    string
	BuildTimeStamp       string
	GitCommitAport       string
	PullDependencies     string
	PackageProvides      string
}

IndexEntry is an APKINDEX entry, a record in a APKINDEX file.

func (*IndexEntry) String

func (entry *IndexEntry) String() string

String converts an IndexEntry to a string

type PkgInfo

type PkgInfo struct {
	PkgName       string
	PkgVer        string
	PkgDesc       string
	PkgUrl        string
	PkgBuildDate  string
	PkgPackager   string
	PkgSize       string
	PkgArch       string
	PkgOrigin     string
	PkgCommit     string
	PkgMaintainer string
	PkgLicense    string
	PkgProvides   []string
	PkgDepends    []string
	PkgDataHash   string
}

PkgInfo is the package info struct for .PKGINFO information from APK files.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL