dolo

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 9 Imported by: 14

README

dolo

Golang module for file download. Dolo skips downloading if the file exists and has the same content length. Dolo supports an optional callback that notifies on progress.

Exported methods

  • NewClient(httpClient *http.Client, notify func(uint64, uint64)) - creates a new dolo client using the provided http.Client (with cookie jar, etc.) and an optional callback to notify on progress. Optional callback takes two values - downloaded bytes and total bytes.

  • Download(url *url.URL, dstDir string, overwrite bool) - downloads a resource at the URL to the destination directory (original resource base path would be used for a filename). Overwrite would require download even if the destination file already exists and has the same content length.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = NewClient(http.DefaultClient, Defaults())

Functions

func CopyWithProgress added in v0.2.0

func CopyWithProgress(dst io.Writer, src io.ReadCloser, tpw nod.TotalProgressWriter) error

func NewFileIndexSetter added in v0.2.0

func NewFileIndexSetter(filenames []string) *fileIndexSetter

func NewResourceContext added in v0.2.0

func NewResourceContext(u *url.URL, pathParts ...string) *resourceContext

Types

type Client

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

func NewClient

func NewClient(httpClient *http.Client, opts *ClientOptions) *Client

func (*Client) Download

func (dc *Client) Download(u *url.URL, tpw nod.TotalProgressWriter, pathParts ...string) error

Download gets remote resource, attempting to resume existing partial downloads if the previous attempt got interrupted. Download supports nod progress reporting. Download will use provided path parts (see NewResourceContext for file name, directory rules), and if no parts were specified - will download to the current working directory and use source URL path base for a filename.

func (*Client) GetSet added in v0.2.0

func (cl *Client) GetSet(
	urls []*url.URL,
	indexSetter IndexSetter,
	tpw nod.TotalProgressWriter) error

GetSet downloads URLs and sets them to storage using indexes. E.g. URLs[index] is expected to be received and set by indexSetter(index). GetSet can use provided http.Client for authenticated requests. Finally, it supports reporting progress via provided nod.TotalProgressWriter object (optional).

type ClientOptions

type ClientOptions struct {
	CheckContentLength bool
	ResumeDownloads    bool
}

func Defaults

func Defaults() *ClientOptions

type IndexSetter added in v0.2.0

type IndexSetter interface {
	Set(int, io.ReadCloser, chan bool, chan error)
	Exists(int) bool
	Len() int
}

Jump to

Keyboard shortcuts

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