download

package module
v2.1.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: BSD-2-Clause Imports: 13 Imported by: 6

README

Package go-download

Project status Build Status Coverage Status Go Report Card GoDoc License

Package go-download provides a library for interruptable, resumable download acceleration with automatic Accept-Ranges support

It Features:

  • Customizable concurrency and/or chunk size. default is 10 goroutines
  • Proxy of download eg. to display a progress bar

Installation

go get -u github.com/joeybloggs/go-download

or if your looking for the standalone client

go get -u github.com/joeybloggs/go-download/cmd/goget

Examples

More examples here

package main

import (
	"log"

	download "github.com/joeybloggs/go-download"
)

func main() {

	// no options specified so will default to 10 concurrent download by default

	f, err := download.Open("https://storage.googleapis.com/golang/go1.8.1.src.tar.gz", nil)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	// f implements io.Reader, write file somewhere or do some other sort of work with it
}

Contributing

Pull requests, bug fixes and issue reports are welcome.

Before proposing a change, please discuss your change by raising an issue.

License

Distributed under BSD 2-clause license, please see license file in code for more details.

Documentation

Overview

Package download provides a library for interruptable, resumable download acceleration with automatic Accept-Ranges support.

see all examples https://github.com/admpub/go-download/tree/master/examples

package main

import (
	"log"

	download "github.com/admpub/go-download"
)

func main() {

	// no options specified so will default to 10 concurrent download by default

	f, err := download.Open("https://storage.googleapis.com/golang/go1.8.1.src.tar.gz", nil)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	// f implements io.Reader, write file somewhere or do some other sort of work with it
}

Index

Constants

View Source
const (
	MB = 1024 * 1024
)

Variables

View Source
var (
	ErrMaximumSizeExceeded = errors.New("Maximum size exceeded")
)

Functions

func Download added in v1.0.1

func Download(url, saveName string, options *Options) (int64, error)

Types

type Canceled

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

Canceled is the error containing the cancelled error information

func (*Canceled) Error

func (e *Canceled) Error() string

Error returns the Canceled error string

type ClientFn added in v1.0.1

type ClientFn func() http.Client

ClientFn allows for a custom http.Client to be used for the http request

type ConcurrencyFn

type ConcurrencyFn func(size int64) int

ConcurrencyFn is the function used to determine the level of concurrency aka the number of goroutines to use. Default concurrency level is 10

if returned value is < 1 then the default value will be used

type DeadlineExceeded

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

DeadlineExceeded is the error containing the deadline exceeded error information

func (*DeadlineExceeded) Error

func (e *DeadlineExceeded) Error() string

Error returns the DeadlineExceeded error string

type File

type File struct {
	io.Reader
	// contains filtered or unexported fields
}

File represents an open file descriptor to a downloaded file(s)

func Open

func Open(url string, options *Options) (*File, error)

Open downloads and opens the file(s) downloaded by the given url

func OpenContext

func OpenContext(ctx context.Context, url string, options *Options) (*File, error)

OpenContext downloads and opens the file(s) downloaded by the given url and is cancellable using the provided context. The context provided must be non-nil

func (*File) Close

func (f *File) Close() error

Close closes the File(s), rendering it unusable for I/O. It returns an error, if any.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat returns the FileInfo structure describing file(s). If there is an error, it will be of type *PathError.

type InvalidResponseCode

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

InvalidResponseCode is the error containing the invalid response code error information

func (*InvalidResponseCode) Error

func (e *InvalidResponseCode) Error() string

Error returns the InvalidResponseCode error string

type Options

type Options struct {
	Concurrency ConcurrencyFn
	Proxy       ProxyFn
	Client      ClientFn
	Request     RequestFn
	MaxSize     int64
}

Options contains any specific configuration values for downloading/opening a file

type ProxyFn

type ProxyFn func(name string, download int, size int64, r io.Reader) io.Reader

ProxyFn is the function used to pass the download io.Reader for proxying. eg. displaying a progress bar of the download.

type RequestFn added in v1.0.1

type RequestFn func(r *http.Request)

RequestFn allows for additional information, such as http headers, to the http request

Do not alter the "Range" http headers or the download can become corrupt

Directories

Path Synopsis
_examples
cmd

Jump to

Keyboard shortcuts

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