utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client = sync.Pool{
	New: func() interface{} {
		return &http.Client{
			Transport: &http.Transport{
				Proxy: http.ProxyFromEnvironment,
				TLSClientConfig: &tls.Config{
					MaxVersion: tls.VersionTLS12,
				},
			},
		}
	},
}
View Source
var (
	ErrUnsupportedMultiThreading = errors.New("unsupported multi-threading")
)

Functions

func PathExists added in v0.3.0

func PathExists(path string) bool

func SingleThreadDownload added in v0.3.0

func SingleThreadDownload(url, path string, headers map[string]string) error

Types

type BlockMetaData added in v0.3.0

type BlockMetaData struct {
	BeginOffset    int64
	EndOffset      int64
	DownloadedSize int64
}

type MultiThreadDownloader added in v0.3.0

type MultiThreadDownloader struct {
	Url         string
	SavePath    string
	FileName    string
	FullPath    string
	Client      *http.Client
	Headers     map[string]string
	Blocks      []*BlockMetaData
	ThreadCount int
}

func NewDownloader added in v0.3.0

func NewDownloader(url string, path string, name string, threadCount int, headers map[string]string) *MultiThreadDownloader

func (*MultiThreadDownloader) Download added in v0.3.0

func (m *MultiThreadDownloader) Download() error

type TaskQueue added in v0.3.0

type TaskQueue chan *MultiThreadDownloader

type Worker added in v0.3.0

type Worker struct {
	TaskChan TaskQueue
}

func NewWorker added in v0.3.0

func NewWorker() *Worker

func (*Worker) Run added in v0.3.0

func (w *Worker) Run(wq chan TaskQueue, owner *WorkerPool)

type WorkerPool added in v0.3.0

type WorkerPool struct {
	sync.WaitGroup

	WorkerCount int
	TaskQueue   TaskQueue
	WorkerQueue chan TaskQueue
}

func NewWorkerPool added in v0.3.0

func NewWorkerPool(WorkerCount int) *WorkerPool

func (*WorkerPool) Start added in v0.3.0

func (wp *WorkerPool) Start()

Jump to

Keyboard shortcuts

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