pluto

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package pluto provides a way to download files at high speeds by using http ranged requests.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrOverflow is when server sends more data than what was requested
	ErrOverflow = "error: Server sent extra bytes"
)

Functions

This section is empty.

Types

type Pluto

type Pluto struct {
	StatsChan chan *Stats
	Finished  chan struct{}

	MetaData fileMetaData
	// contains filtered or unexported fields
}

Pluto contains all the details that Download needs. Connections is the number of connections to use to download a file Verbose is to enable verbose mode. Writer is the place where downloaded data is written. Headers is any header that you may need to send to download the file. StatsChan is a channel to which Stats are sent, It can be nil or a channel that can hold data of type *()

func New

func New(up *url.URL, headers []string, connections uint, verbose bool) (*Pluto, error)

New returns a pluto instance

func (*Pluto) Download

func (p *Pluto) Download(ctx context.Context, w io.WriterAt) (*Result, error)

Download takes Config struct then downloads the file by dividing it into given number of parts and downloading all parts concurrently. If any error occurs in the downloading stage of any part, It'll check if the the program can recover from error by retrying download And if an error occurs which the program can not recover from, it'll return that error

type Result

type Result struct {
	FileName  string
	Size      uint64
	AvgSpeed  float64
	TimeTaken time.Duration
}

Result is the download results

type Stats

type Stats struct {
	Downloaded uint64
	Speed      uint64
	Size       uint64
}

Stats is returned in a channel by Download function every 250ms and contains details like Current download speed in bytes/sec and amount of data Downloaded

Jump to

Keyboard shortcuts

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