dl

package
v0.1.1-0...-c2b0454 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DataDirectory = ".ldss"

The directory to read and store the gospel library cache and configurations

Functions

func Enqueue

func Enqueue(d Downloader, ret chan<- Status)

Enqueue queues a Downloader to be downloaded. If ret is passed it will receive updates for the download. Can be nil to ignore.

NOTE: If multiple subscribers to a single download are wanted. That could be implemented in the future by calling the function again with the same Downloader, but for now, DO NOT PASS THE SAME DOWNLOADER MORE THAN ONCE.

func EnqueueAndWait

func EnqueueAndWait(d Downloader) (err error)

EnqueueAndWait enques a download, waits for completion, and returns its error if any.

func ErrNotDownloaded

func ErrNotDownloaded(d Downloader) error

func Listen

func Listen(updates chan<- DownloadStatus)

Listen subscribes to events in download status. All uncompleted downloads are immediately passed in so the subscriber will know of their existance and current state.

Types

type DownloadStatus

type DownloadStatus struct {
	Downloader
	Status
	Stage Stage
}

type Downloader

type Downloader interface {
	Downloaded() bool
	Download(chan<- Status) error
	Name() string
	Hash() string
}

func IsNotDownloaded

func IsNotDownloaded(err error) (Downloader, bool)

type Stage

type Stage byte
const (
	// Waiting indicates the download is queued, but not yet started.
	Waiting Stage = iota

	// Started indiciates the download has been started, but has not given
	// any status updates, so the Progress should be ignored.
	Started

	// Progress indicates that the download is progressing and Progress
	// is accurate.
	Progress

	// Complete indicates that the download is complete, and will receive
	// no further updates. Err should be checked to see if the download
	// was a success.
	Complete
)

type Status

type Status struct {
	Err      error
	Progress float64
}

type Template

type Template struct {
	Src       string
	Dest      string
	Transform func(io.Reader) (io.ReadCloser, error)
}

func (Template) Download

func (t Template) Download(chan<- Status) error

https://gist.github.com/albulescu/e61979cc852e4ee8f49c to download with progress The best way to do it is to create a reader that can eavesdrop on the transform reading, so compression, etc. won't matter. The gist has a good example of getting the content length. If the length cannot be gotten, we just won't send status updates. (This is good because renderers should display this correctly).

func (Template) Downloaded

func (t Template) Downloaded() bool

Jump to

Keyboard shortcuts

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