download

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedHTTPStatus = errors.New("unexpected http status")

Functions

This section is empty.

Types

type BufferMode

type BufferMode struct {
	Client *client.HTTPClient
	Options
	// contains filtered or unexported fields
}

func GetBufferMode added in v0.2.1

func GetBufferMode(opts Options) *BufferMode

func (*BufferMode) DoRequest added in v0.4.0

func (m *BufferMode) DoRequest(ctx context.Context, start, end int64, trueURL string) (*http.Response, error)

func (*BufferMode) Fetch added in v0.2.1

func (m *BufferMode) Fetch(ctx context.Context, url string) (io.Reader, int64, error)

func (*BufferMode) Wait added in v0.7.1

func (m *BufferMode) Wait() error

type CacheKey added in v0.4.0

type CacheKey struct {
	URL   *url.URL `hash:"string"`
	Slice int64
}

type ConsistentHashingMode added in v0.3.2

type ConsistentHashingMode struct {
	Client *client.HTTPClient
	Options
	// TODO: allow this to be configured and not just "BufferMode"
	FallbackStrategy Strategy
	// contains filtered or unexported fields
}

func GetConsistentHashingMode added in v0.3.2

func GetConsistentHashingMode(opts Options) (*ConsistentHashingMode, error)

func (*ConsistentHashingMode) DoRequest added in v0.4.0

func (m *ConsistentHashingMode) DoRequest(ctx context.Context, start, end int64, urlString string) (*http.Response, error)

func (*ConsistentHashingMode) Fetch added in v0.3.2

func (m *ConsistentHashingMode) Fetch(ctx context.Context, urlString string) (io.Reader, int64, error)

func (*ConsistentHashingMode) Wait added in v0.7.1

func (m *ConsistentHashingMode) Wait() error

type ErrContentLengthMismatch added in v0.7.1

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

func (ErrContentLengthMismatch) Error added in v0.7.1

func (err ErrContentLengthMismatch) Error() string

type Options added in v0.2.0

type Options struct {
	// Maximum number of chunks to download. If set to zero, GOMAXPROCS*4
	// will be used.
	MaxConcurrency int

	// SliceSize is the number of bytes per slice in nginx.
	// See https://nginx.org/en/docs/http/ngx_http_slice_module.html
	SliceSize int64

	// Number of bytes per chunk. If set to zero, 125 MiB will be used.
	ChunkSize int64

	Client client.Options

	// CacheableURIPrefixes is an allowlist of domains+path-prefixes which may
	// be routed via a pull-through cache
	CacheableURIPrefixes map[string][]*url.URL

	// CacheUsePathProxy is a flag to indicate whether to use the path proxy mechanism or the host-based mechanism
	// The default is to use the host-based mechanism, the path proxy mechanism is used when this flag is set to true
	// and involves prepending the host to the path of the request to the cache. In both cases the Hosts header is
	// sent to the cache.
	CacheUsePathProxy bool

	// CacheHosts is a slice of hostnames to use as pull-through caches.
	// The ordering is significant and will be used with the consistent
	// hashing algorithm.  The slice may contain empty entries which
	// correspond to a cache host which is currently unavailable.
	CacheHosts []string
}

type Strategy added in v0.2.1

type Strategy interface {
	// Fetch retrieves the content from a given URL and returns it as an io.Reader along with the file size.
	// If an error occurs during the process, it returns nil for the reader, 0 for the fileSize, and the error itself.
	// This is the primary method that should be called to initiate a download of a file.
	Fetch(ctx context.Context, url string) (result io.Reader, fileSize int64, err error)

	// Wait waits until all requests have completed, and returns the first error encountered, if any.
	Wait() error

	// DoRequest sends an HTTP GET request with a specified range of bytes to the given URL using the provided context.
	// It returns the HTTP response and any error encountered during the request. It is intended that Fetch calls DoRequest
	// and that each chunk is downloaded with a call to DoRequest. DoRequest is exposed so that consistent-hashing can
	// utilize any strategy as a fall-back for chunk downloading.
	//
	// If the request fails to download or execute, an error is returned.
	//
	// The start and end parameters specify the byte range to request.
	// The trueURL parameter is the actual URL after any redirects.
	DoRequest(ctx context.Context, start, end int64, url string) (*http.Response, error)
}

Jump to

Keyboard shortcuts

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