acquire

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package acquire coordinates package artifact resolution, downloading, integrity verification, and storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound reports that a store has no artifact matching a request.
	ErrNotFound = errors.New("artifact not found")
	// ErrOffline reports that acquisition would require an upstream request.
	ErrOffline = errors.New("artifact unavailable offline")
	// ErrTooLarge reports that an artifact exceeds the configured byte limit.
	ErrTooLarge = errors.New("artifact exceeds size limit")
)

Functions

This section is empty.

Types

type Download

type Download struct {
	Body      io.ReadCloser
	Size      int64
	MediaType string
}

Download is a streaming upstream response. Size is -1 when unavailable.

type Entry

type Entry struct {
	Artifact artifacts.Artifact
	Body     io.ReadCloser
}

Entry is a completed artifact opened from a Store.

type Fetcher

type Fetcher interface {
	Fetch(context.Context, string) (*Download, error)
}

Fetcher opens an upstream URL. The returned body belongs to the caller.

type Options

type Options struct {
	Offline  bool
	MaxBytes int64
}

Options controls one acquisition.

type Request

type Request struct {
	PURL      string
	Filename  string
	Integrity integrity.SRI
}

Request identifies one package artifact. Filename and Integrity may narrow a version that has several published files.

type Resolver

type Resolver interface {
	Resolve(context.Context, Request) (Source, error)
}

Resolver selects an upstream file for a canonical, versioned request.

type Result

type Result struct {
	Artifact artifacts.Artifact
	Body     io.ReadCloser
	Cached   bool
}

Result is an acquired artifact and a reader positioned at its first byte.

type Service

type Service struct {
	Resolver Resolver
	Fetcher  Fetcher
	Store    Store
}

Service acquires package artifacts through supplied resolver, fetcher, and store implementations.

func (Service) Acquire

func (service Service) Acquire(ctx context.Context, request Request, options Options) (*Result, error)

Acquire returns a matching stored artifact or resolves and fetches one.

func (Service) AcquireFrom

func (service Service) AcquireFrom(ctx context.Context, request Request, source Source, options Options) (*Result, error)

AcquireFrom returns a matching stored artifact or fetches the supplied source. It supports callers that already obtained an exact artifact URL.

type Source

type Source struct {
	URL       string
	Filename  string
	MediaType string
	Integrity integrity.SRI
}

Source describes the upstream file selected for a request. Integrity is used when the request did not supply lockfile integrity metadata.

type Stage

type Stage interface {
	io.Writer
	Commit(context.Context, artifacts.Artifact) (io.ReadCloser, error)
	Discard(context.Context) error
}

Stage receives unverified bytes. Commit publishes them and returns a fresh reader. Discard removes an unpublished stage.

type Store

type Store interface {
	Open(context.Context, Request) (*Entry, error)
	Stage(context.Context, Request, Source) (Stage, error)
}

Store finds completed artifacts and creates private staging writes.

Open must return ErrNotFound when no completed artifact matches every populated Request field. A Stage must remain unavailable through Open until Commit succeeds.

Jump to

Keyboard shortcuts

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