download

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WriteBufferSize           = 64 * 1024        // 64 KiB
	DiskAllocationWarningSize = 24 * 1024 * 1024 // 24 MiB
	ProgressCompletedSize     = 10000
)
View Source
const (
	RefreshRate        = 120 * time.Millisecond
	SpeedAverageWindow = 45.0 // 45 seconds
	BarStyle           = "|-> |"
)

Variables

View Source
var (
	NewID chan int64
)

Functions

func AddGlobalProgressBar added in v0.1.4

func AddGlobalProgressBar(d *Download)

func AddLocalProgressBar added in v0.1.4

func AddLocalProgressBar(index int, pieceCount int, r *ByteRange)

func DownloadPath

func DownloadPath(defaultFileName string) string

func InitializeProgress added in v0.1.4

func InitializeProgress(width int)

func ShutdownProgress added in v0.1.4

func ShutdownProgress(success bool)

Types

type ByteRange added in v0.1.6

type ByteRange struct {
	Start     int64
	End       int64
	Wrote     int64
	Progress  int64
	LastWrote time.Time
}

func NewByteRange added in v0.1.6

func NewByteRange(start, end, wrote int64) *ByteRange

func (*ByteRange) String added in v0.1.6

func (r *ByteRange) String() string

type BytesWrote added in v0.1.6

type BytesWrote struct {
	Wrote    int
	Duration time.Duration
}

type ControlFile added in v0.1.4

type ControlFile struct {
	URLs   []string
	Ranges []*ByteRange
}

func ParseControlFile added in v0.1.4

func ParseControlFile(filePath string) (*ControlFile, error)

func (*ControlFile) String added in v0.1.4

func (cf *ControlFile) String() string

type ControlWriter added in v0.1.6

type ControlWriter struct {
	io.WriterAt

	Cancelled chan bool
	// contains filtered or unexported fields
}

func NewControlWriter added in v0.1.6

func NewControlWriter(w io.WriterAt, offset int64) *ControlWriter

func (*ControlWriter) Write added in v0.1.6

func (w *ControlWriter) Write(b []byte) (n int, err error)

type Download

type Download struct {
	ID             int64
	Status         int
	URL            string
	Name           string
	Size           int64
	Remaining      int64
	SupportsRange  bool
	Ranges         []*ByteRange
	Writers        []*DownloadWriter
	ControlWriters []*ControlWriter
	FilePath       string
	Started        time.Time
	Finished       time.Time
	WasPaused      bool

	Retries    int
	InProgress bool
	Paused     bool
	Cancelled  bool

	*sync.RWMutex
	// contains filtered or unexported fields
}

func NewDownload

func NewDownload(url string, postData []byte) (*Download, error)

func (*Download) Cancel added in v0.1.3

func (d *Download) Cancel()

func (*Download) Download

func (d *Download) Download(postData []byte) error

func (*Download) GetDownloaded added in v0.1.4

func (d *Download) GetDownloaded() int64

func (*Download) GetStatus added in v0.1.3

func (d *Download) GetStatus() int

func (*Download) GetVerboseDownloaded added in v0.1.6

func (d *Download) GetVerboseDownloaded() []byte

func (*Download) Pause added in v0.1.4

func (d *Download) Pause()

func (*Download) Resume added in v0.1.5

func (d *Download) Resume()

func (*Download) Wait

func (d *Download) Wait()

type DownloadWriter added in v0.1.6

type DownloadWriter struct {
	io.WriterAt
	Range     *ByteRange
	Cancelled bool
}

func NewDownloadWriter added in v0.1.6

func NewDownloadWriter(w io.WriterAt, r *ByteRange) *DownloadWriter

func (*DownloadWriter) Write added in v0.1.6

func (w *DownloadWriter) Write(b []byte) (n int, err error)

type GlobalBarInfo added in v0.1.4

type GlobalBarInfo struct {
	Name     string
	Size     int64
	Pieces   int
	Progress chan *BytesWrote
}

type Metadata

type Metadata struct {
	Name          string
	Size          int64
	SupportsRange bool
}

func FetchMetadata

func FetchMetadata(url string, postData []byte) (*Metadata, error)

type RangeBarInfo added in v0.1.4

type RangeBarInfo struct {
	Index    int
	Size     int64
	Progress chan *BytesWrote
}

Jump to

Keyboard shortcuts

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