www

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(url, root, path, fname string, opts ...RequestOpt) (string, int64, error)

Download attempts to download a file into specified location. Returns contentType or error.

func DownloadContent

func DownloadContent(url, root, path string) (string, []byte, string, int64, error)

DownloadContent attempts to download a file into specified location and returns the downloaded file external path and the body along with contentType.

func EnqueueDownload

func EnqueueDownload(url, root, path string, sct SetContentType) (extPath string, contentType string, fileSize int64, err error)

EnqueueDownload makes one attempt to download file synchronously and in case of timeout run the ansychronous process with a log scale retry policy. If the file was downloaded at first attempt, the contentType is not empty.

func Fetch

func Fetch(url, root, path, fname string, buf io.Writer, opts ...RequestOpt) (contentType string, newURL *url.URL, fileSize int64, err error)

Fetch downloads a file specified in uri, saves it to root+path+fname (if fname specified), copies the body content into buf (if buf specified) and returns newURL if redirect occured.

func FetchContent

func FetchContent(url string, opts ...RequestOpt) ([]byte, string, *url.URL, int64, error)

FetchContent attempts to download a file and return its content along with a new URL if redirect occured.

Types

type RequestOpt

type RequestOpt int
const (
	ReqIgnore403 RequestOpt = 1 // forbidden
	ReqIgnore404 RequestOpt = 2 // not found
	ReqIgnore406 RequestOpt = 3 // not acceptable
	ReqIgnore410 RequestOpt = 4 // gone
	ReqIgnore451 RequestOpt = 5 // unavailable for leagal reasons
)

type SetContentType

type SetContentType func(url, contentType string, fileSize int64)

SetContentType is a callback function which receives a contentType of a downloaded file once it has beed saved to disk

type WWWInterface

type WWWInterface interface {
	// async download to file
	EnqueueDownload(url, root, path string) (extPath string, err error)
	// sync download to file
	Download(url, root, path, name string) error
	// sync
	DownloadContent(url, root, path string) (string, []byte, string, error)
	FetchContent(url, root, path string) ([]byte, string, error)
}

Jump to

Keyboard shortcuts

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