downloader

package
v0.0.0-...-c491b3c Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCheckSumUnmatched = errors.New("check sum unmatched")

Functions

func Untar

func Untar(ctx context.Context, storage afero.Fs, r io.Reader, dirMask fs.FileMode) error

Types

type ArchiverAlgo

type ArchiverAlgo string
const (
	Tar ArchiverAlgo = "tar"
)

func (ArchiverAlgo) Unarchive

func (a ArchiverAlgo) Unarchive(ctx context.Context, storage afero.Fs, r io.Reader) error

type ChecksumEncoding

type ChecksumEncoding string
const (
	Base64 ChecksumEncoding = "base64"
	Hex    ChecksumEncoding = "hex"
)

func (ChecksumEncoding) Decode

func (e ChecksumEncoding) Decode(data string) ([]byte, error)

func (ChecksumEncoding) Encode

func (e ChecksumEncoding) Encode(data []byte) string

type CompressionAlgo

type CompressionAlgo string
const (
	Bzip2 CompressionAlgo = "bzip2"
	Flate CompressionAlgo = "flate"
	Gzip  CompressionAlgo = "gzip"
	// Lzw   CompressionAlgo = "lzw"
	Zlib CompressionAlgo = "zlib"
)

func (CompressionAlgo) Decompress

func (a CompressionAlgo) Decompress(r io.Reader) (io.ReadCloser, error)

type DownloadTask

type DownloadTask struct {
	// Download destination path. Dest should be slash delimited.
	Dest string
	// Target url
	Url      *url.URL
	Validity Validity
}

type DownloadTaskState

type DownloadTaskState struct {
	State        State
	Downloaded   *atomic.Int64
	DownloadTask DownloadTask
	Err          error
	// contains filtered or unexported fields
}

func NewDownloadTaskState

func NewDownloadTaskState(t DownloadTask) *DownloadTaskState

func (*DownloadTaskState) Snapshot

type DownloaderWorker

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

func NewDownloaderWorker

func NewDownloaderWorker(
	storage afero.Fs,
	safeWriteConfig SafeWriteConfig,
	limit uint,
	requester Requester,
) *DownloaderWorker

func (*DownloaderWorker) Run

func (w *DownloaderWorker) Run(ctx context.Context)

func (*DownloaderWorker) Send

func (w *DownloaderWorker) Send(t *DownloadTaskState)

type Requester

type Requester interface {
	Request(ctx context.Context, target *url.URL) (io.ReadCloser, error)
}

type RequesterFunc

type RequesterFunc func(ctx context.Context, target *url.URL) (io.ReadCloser, error)

func (RequesterFunc) Request

func (f RequesterFunc) Request(ctx context.Context, target *url.URL) (io.ReadCloser, error)

type SafeWriteConfig

type SafeWriteConfig struct {
	TempDir       string
	DirMask       fs.FileMode
	ForceDirMask  bool
	ForceFileMask bool
}

func (SafeWriteConfig) RemoveTemp

func (c SafeWriteConfig) RemoveTemp(storage afero.Fs) error

func (SafeWriteConfig) SafeWrite

func (c SafeWriteConfig) SafeWrite(
	storage afero.Fs,
	dest string,
	filePerm fs.FileMode,
	r io.Reader,
	postProcess ...(func(filename string, written int64) error),
) (err error)

type State

type State string
const (
	StateWaiting       State = "waiting"
	StateDownloading   State = "downloading"
	StateConcatenating State = "concatenating"
	StateDone          State = "done"
	StateErr           State = "err"
)

type StaticDownloadTaskState

type StaticDownloadTaskState struct {
	State        State
	Downloaded   int64
	DownloadTask DownloadTask
	Err          error
}

type StaticTaskState

type StaticTaskState struct {
	State             State
	Downloaded        int64
	Task              Task
	DownloadTaskState []StaticDownloadTaskState
	Err               error
}

type Task

type Task struct {
	// Download destination path. Dest should be slash delimited.
	Dest            string
	ArchiveAlgo     ArchiverAlgo
	CompressionAlgo CompressionAlgo
	Validity        Validity
	Tasks           []DownloadTask
}

type TaskState

type TaskState struct {
	State             State
	Downloaded        *atomic.Int64
	Task              Task
	DownloadTaskState []*DownloadTaskState
	Err               error
	// contains filtered or unexported fields
}

func NewTaskState

func NewTaskState(t Task) *TaskState

func (*TaskState) Snapshot

func (t *TaskState) Snapshot() StaticTaskState

type Validity

type Validity struct {
	Size             int
	Checksum         string
	ChecksumEncoding ChecksumEncoding
	ChecksumAlgo     crypto.Hash
}

func (Validity) Hash

func (v Validity) Hash() (h hash.Hash, ok bool)

func (Validity) Validate

func (v Validity) Validate(b []byte) error

Jump to

Keyboard shortcuts

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