downloader

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package downloader provides a simple file downlaoder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileDownloader

type FileDownloader struct {
	SaveDir       string       // path of the directory to save the downloaded file
	DefaultHeader http.Header  // Default header to applied to the download request
	Client        *http.Client // HTTP client to use, default is http DefaultClient
	ProxyReader   ProxyReader
}

FileDownloader is a file downloader

func New

func New(saveDir string) *FileDownloader

New creates a file downloader

func (*FileDownloader) Download

func (d *FileDownloader) Download(url string) (dest string, size int64, err error)

Download downloads a file from a URL and returns the path and size of the downloaded file

func (*FileDownloader) DownloadTo

func (d *FileDownloader) DownloadTo(url string, outputName string) (dest string, size int64, err error)

DownloadTo downloads a file from a URL to the file with the specified name in the download directory

func (*FileDownloader) RemoveDir

func (d *FileDownloader) RemoveDir() error

RemoveDir removes the download directory

type ProgressBar

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

ProgressBar is an implementation of ProxyReader that displays a process bar during file downloading.

func NewProgressBar

func NewProgressBar(out io.Writer) *ProgressBar

func (*ProgressBar) Finish

func (p *ProgressBar) Finish()

func (*ProgressBar) Proxy

func (p *ProgressBar) Proxy(totalSize int64, reader io.Reader) io.Reader

type ProxyReader

type ProxyReader interface {
	Proxy(size int64, reader io.Reader) io.Reader
	Finish()
}

ProxyReader is an interface to proxy read bytes

Jump to

Keyboard shortcuts

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