download

package
v1.3.43 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDownloadWorker = 5
)

Variables

This section is empty.

Functions

func GetDownloadErrors

func GetDownloadErrors(results []FileDownloadResult) map[string]error

returns a map of failed downloads

func GetSuccessfulDownloads

func GetSuccessfulDownloads(results []FileDownloadResult) int

returns count of successful downloads

func HasDownloadErrors

func HasDownloadErrors(results []FileDownloadResult) bool

checks if any results contain errors

func IsWithinDest

func IsWithinDest(destDir, registryPath string) bool

IsWithinDest reports whether a registry path resolves to a location inside destDir. Used to reject crafted paths like "../../evil.txt" before they can escape the download destination.

func ResolveDestPath

func ResolveDestPath(destDir, registryPath string) string

ResolveDestPath returns the OS-native filesystem path where a file with the given registry path would be written under destDir.

Types

type BaseFileDownloadJob

type BaseFileDownloadJob struct {
	ID       string
	FilePath string
	FileSize int64
}

BaseFileDownloadJob provides common fields for download jobs.

func (*BaseFileDownloadJob) GetFilePath

func (b *BaseFileDownloadJob) GetFilePath() string

func (*BaseFileDownloadJob) GetFileSize

func (b *BaseFileDownloadJob) GetFileSize() int64

func (*BaseFileDownloadJob) GetID

func (b *BaseFileDownloadJob) GetID() string

type FileDownloadEngine

type FileDownloadEngine struct {
	// contains filtered or unexported fields
}

manages concurrent file downloads

func NewFileDownloadEngine

func NewFileDownloadEngine(maxWorkers int, progress p.Reporter) *FileDownloadEngine

creating a new download engine, to perform downloads concurrently

func (*FileDownloadEngine) Execute

Execute runs all download jobs concurrently.

type FileDownloadJob

type FileDownloadJob interface {
	GetID() string
	GetFilePath() string
	GetFileSize() int64
	Download(ctx context.Context) error
}

FileDownloadJob represents a single file download operation.

type FileDownloadResult

type FileDownloadResult struct {
	JobID    string
	FilePath string
	FileSize int64
	Error    error
	Success  bool
}

FileDownloadResult holds the outcome of one download job.

type URLDownloadJob

type URLDownloadJob struct {
	BaseFileDownloadJob
	RegistryPath string
	DestDir      string
	DownloadURL  string
	HTTPClient   *http.Client
}

URLDownloadJob downloads a single file from a direct URL. It works for any artifact type since it uses the downloadUrl returned by the search API rather than a type-specific client.

func NewURLDownloadJob

func NewURLDownloadJob(id, registryPath, destDir, downloadURL string, fileSize int64) *URLDownloadJob

func (*URLDownloadJob) Download

func (j *URLDownloadJob) Download(ctx context.Context) error

Jump to

Keyboard shortcuts

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