fetch

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package fetch for download, provide high performance download

use Goroutine to parallel download, use WaitGroup to do concurrency control.

Index

Examples

Constants

View Source
const (
	FileFlag = os.O_WRONLY | os.O_CREATE
	FileMode = 0644
)

FileFlag save file flag

FileMode save file mode

Variables

View Source
var (
	WaitPool = sync.WaitGroup{}
)

WaitPool implement request pool to enhance performance

Functions

func GetFileLength

func GetFileLength(url string) (int64, error)

GetFileLength will return http response content-length example:

GetFileLength("http://xxx")
Example
requestURL := "http://httpbin.org/bytes/%d"

var length1K int64 = 1024
lengthResult, _ := GetFileLength(fmt.Sprintf(requestURL, length1K))
fmt.Println(lengthResult)
Output:

1024

func GoroutineDownload

func GoroutineDownload(requestURL string, poolSize, chunkSize, timeout int64)

GoroutineDownload will download form requestURL. example:

requestURL := "http://xxx"
GoroutineDownload(requestURL, 20, 10*1024*1024, 30)

Types

This section is empty.

Jump to

Keyboard shortcuts

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