fetchup

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 16 Imported by: 4

README

Overview

A lib to fetch the target file from remote. It will auto choose the fastest url to download and decompress the file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDir

func CacheDir() string

func StripFirstDir

func StripFirstDir(dir string) error

StripFirstDir removes the first dir but keep all its children.

Types

type DefaultTransport

type DefaultTransport struct {
	UA string
}

DefaultTransport is the default http transport for fetchup, it auto handles the gzip and user-agent.

func (*DefaultTransport) RoundTrip

func (t *DefaultTransport) RoundTrip(req *http.Request) (*http.Response, error)

type ErrNoURLs

type ErrNoURLs struct {
	URLs []string
}

func (*ErrNoURLs) Error

func (e *ErrNoURLs) Error() string

type Event

type Event string
const (
	EventDownload   Event = "Download:"
	EventProgress   Event = "Progress:"
	EventUnzip      Event = "Unzip:"
	EventDownloaded Event = "Downloaded:"
)

type Fetchup

type Fetchup struct {
	Ctx context.Context

	// To is the path to save the file.
	To string

	// URLs is the list of candidates, the fastest one will be used to download the file.
	URLs []string

	Logger Logger

	// SpeedPacketSize is the size of the packet used to calculate the download speed.
	// The size should be much smaller than the whole file size to download.
	SpeedPacketSize int

	MinReportSpan time.Duration

	HttpClient *http.Client
}

func New

func New(to string, us ...string) *Fetchup

func (*Fetchup) Download

func (fu *Fetchup) Download(u string) error

func (*Fetchup) FastestURL

func (fu *Fetchup) FastestURL() (fastest string)

func (*Fetchup) Fetch

func (fu *Fetchup) Fetch() error

func (*Fetchup) Request

func (fu *Fetchup) Request(u string) (*Response, error)

func (*Fetchup) UnTar

func (fu *Fetchup) UnTar(r io.Reader) error

func (*Fetchup) UnZip

func (fu *Fetchup) UnZip(r io.Reader) error

type Log

type Log func(msg ...interface{})

Log type for Println

func MultiLogger

func MultiLogger(list ...Logger) Log

MultiLogger is similar to https://golang.org/pkg/io/#MultiWriter

func (Log) Println

func (l Log) Println(msg ...interface{})

Println interface

type Logger

type Logger interface {
	// Same as fmt.Printf
	Println(...interface{})
}

Logger interface

var LoggerQuiet Logger = Log(func(_ ...interface{}) {})

LoggerQuiet does nothing

type Response

type Response struct {
	Req            *http.Request
	ResHeader      http.Header
	ProgressedBody io.Reader
	Close          func()
}

Jump to

Keyboard shortcuts

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