...

Package download

Overview ▾

Constants

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

Variables

var (
    NewID chan int64
)

func AddGlobalProgressBar

func AddGlobalProgressBar(d *Download)

func AddLocalProgressBar

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

func DownloadPath

func DownloadPath(defaultFileName string) string

func InitializeProgress

func InitializeProgress(width int)

func ShutdownProgress

func ShutdownProgress(success bool)

type ByteRange

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

func NewByteRange

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

func (*ByteRange) String

func (r *ByteRange) String() string

type BytesWrote

type BytesWrote struct {
    Wrote    int
    Duration time.Duration
}

type ControlFile

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

func ParseControlFile

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

func (*ControlFile) String

func (cf *ControlFile) String() string

type ControlWriter

type ControlWriter struct {
    io.WriterAt

    Cancelled chan bool
    // contains filtered or unexported fields
}

func NewControlWriter

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

func (*ControlWriter) Write

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

func (d *Download) Cancel()

func (*Download) Download

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

func (*Download) GetDownloaded

func (d *Download) GetDownloaded() int64

func (*Download) GetStatus

func (d *Download) GetStatus() int

func (*Download) GetVerboseDownloaded

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

func (*Download) Pause

func (d *Download) Pause()

func (*Download) Resume

func (d *Download) Resume()

func (*Download) Wait

func (d *Download) Wait()

type DownloadWriter

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

func NewDownloadWriter

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

func (*DownloadWriter) Write

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

type GlobalBarInfo

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

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