Documentation ¶
Index ¶
- Variables
- func DownloadStream(ctx context.Context, url, filePath string, writer io.Writer) (err error)
- func DownloadStreamOpts(ctx context.Context, url, filePath string, writer io.Writer, options Options) (err error)
- func FetchURLInfo(ctx context.Context, url string, timeout time.Duration) (contentLength int64, resumable bool, err error)
- type Logger
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoMoreRetries is returned when all retry attempts at downloading have failed ErrNoMoreRetries = errors.New("no download attempts remaining") // ErrInconsistentDownload is returned when the Content-Length header is not equal to the bytes received ErrInconsistentDownload = errors.New("inconsistent download") // ErrDownloadComplete is returned when a download is already completed ErrDownloadComplete = errors.New("download already complete") )
Functions ¶
func DownloadStream ¶
DownloadStream downloads the file at the given URL to the filepath, while also sending a stream to the given writer while retrying any broken connections. Consecutive calls with the same URL and filePath will attempt to resume the download. The download stream written to the writer will then be replayed from the beginning of the download. With the given context the whole operation can be aborted.
func DownloadStreamOpts ¶
func DownloadStreamOpts(ctx context.Context, url, filePath string, writer io.Writer, options Options) (err error)
DownloadStreamOpts is the same as DownloadStream, but allows you to override the default options with own values. See DownloadStream for more information.
func FetchURLInfo ¶
func FetchURLInfo(ctx context.Context, url string, timeout time.Duration) (contentLength int64, resumable bool, err error)
FetchURLInfo does a HEAD request to see if the download URL is valid and returns the size of the content. Also checks if the download can be resumed by looking at capability headers.
Types ¶
type Logger ¶
type Logger interface { Infof(format string, args ...interface{}) Errorf(format string, args ...interface{}) }
Logger is an optional interface used for outputting debug logging
type Options ¶
type Options struct { Timeout time.Duration InitialHeadTimeout time.Duration RetryWait time.Duration Retries int RetryWaitMultiplier float64 FileMode os.FileMode BufferSize int HTTPTransport http.RoundTripper Logger Logger }
Options are a set of options used while downloading a stream
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions are the default options used when no options are specified by users of the library. Call this function to get a new default options struct where you can adjust only the things you need to.