expandapk

package
v1.2.43 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 21 Imported by: 3

Documentation

Index

Constants

View Source
const DefaultMaxControlSize int64 = 10 << 20

DefaultMaxControlSize is the default maximum decompressed size for control sections (10 MB).

View Source
const DefaultMaxDataSize int64 = 16 << 30

DefaultMaxDataSize is the default maximum decompressed size for data sections (~17 GB).

Variables

This section is empty.

Functions

func Split

func Split(source io.Reader) ([]io.Reader, error)

Split takes an APK reader and splits it into its constituent parts.

If the length of the returned slice is 3, the first part is the signature section. If the length of the returned slice is 2, the first part is the control section. The last part is the data section.

These values are the compressed gzip streams, and should be decompressed before use.

The signature and control sections are buffered in memory, while the data section is streamed from the input reader.

func SplitWithOptions added in v1.1.0

func SplitWithOptions(source io.Reader, opts ...Option) ([]io.Reader, error)

SplitWithOptions is like Split but accepts functional options to configure size limits for APK sections.

Types

type APKExpanded

type APKExpanded struct {
	// The size in bytes of the entire apk (sum of all tar.gz file sizes)
	Size int64

	// Whether or not the apk contains a signature
	// Note: currently unused
	Signed bool

	// The package signature filename (a.k.a. ".SIGN...") in tar.gz format
	SignatureFile string

	// The control data filename (a.k.a. ".PKGINFO") in tar.gz format
	ControlFile string

	// The package data filename in .tar.gz format
	PackageFile string

	// The package data filename in .tar format.
	TarFile string

	// Expose ControlFile as an indexed FS implementation.
	ControlFS *tarfs.FS

	// Exposes TarFile as an indexed FS implementation.
	TarFS *tarfs.FS

	ControlHash   []byte
	PackageHash   []byte
	SignatureHash []byte

	ControlSize   int64
	PackageSize   int64
	SignatureSize int64

	sync.Mutex
	// contains filtered or unexported fields
}

APKExpanded contains information about and reference to an expanded APK package. Close() deletes all temporary files and directories created during the expansion process.

func ExpandApk

func ExpandApk(ctx context.Context, source io.Reader, cacheDir string) (*APKExpanded, error)

ExpandAPK given a ready to an apk stream, normally a tar stream with gzip compression, expand it into its components.

An apk is split into either 2 or 3 file streams (2 for unsigned packages, 3 for signed).

For more info, see https://wiki.alpinelinux.org/wiki/Apk_spec:

"APK v2 packages contain two tar segments followed by a tarball each in their
own gzip stream (3 streams total). These streams contain the package signature,
control data, and package data"

Returns an APKExpanded struct containing references to the file. You *must* call APKExpanded.Close() when finished to clean up the various files.

func ExpandApkWithOptions added in v1.1.0

func ExpandApkWithOptions(ctx context.Context, source io.Reader, cacheDir string, opts ...Option) (*APKExpanded, error)

ExpandApkWithOptions is like ExpandApk but accepts functional options to configure size limits for APK sections.

func (*APKExpanded) APK

func (a *APKExpanded) APK() (io.ReadCloser, error)

func (*APKExpanded) Close

func (a *APKExpanded) Close() error

func (*APKExpanded) ControlData

func (a *APKExpanded) ControlData() ([]byte, error)

func (*APKExpanded) IsValid added in v0.30.35

func (a *APKExpanded) IsValid() bool

IsValid checks that the expanded APK is still valid by verifying that the underlying files exist and that the file handles match the expected files. Since this structure is heavily cached, this is useful to verify that the cached data is still valid.

func (*APKExpanded) PackageData

func (a *APKExpanded) PackageData() (*os.File, error)

func (*APKExpanded) PkgInfo added in v1.0.2

func (a *APKExpanded) PkgInfo() (*types.PackageInfo, error)

PkgInfo parses and returns the .PKGINFO file.

type Option added in v1.1.0

type Option func(*Options) error

Option is a functional option for configuring Options.

func WithMaxControlSize added in v1.1.0

func WithMaxControlSize(size int64) Option

WithMaxControlSize sets the maximum decompressed size for signature and control sections.

func WithMaxDataSize added in v1.1.0

func WithMaxDataSize(size int64) Option

WithMaxDataSize sets the maximum decompressed size for the data section.

type Options added in v1.1.0

type Options struct {
	// MaxControlSize is the maximum decompressed size for signature and control sections.
	// Use -1 for unlimited.
	MaxControlSize int64

	// MaxDataSize is the maximum decompressed size for the data section.
	// Use -1 for unlimited.
	MaxDataSize int64
}

Options configures the behavior of APK expansion operations.

func DefaultOptions added in v1.1.0

func DefaultOptions() *Options

DefaultOptions returns Options with default size limits.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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