Documentation
¶
Index ¶
- Constants
- Variables
- type GoDownload
- func (gd *GoDownload) Download(path string, opt *Options) error
- func (gd *GoDownload) DownloadContext(ctx context.Context, path string, opt *Options) error
- func (gd *GoDownload) DownloadHF(repo string, opt *Options) error
- func (gd *GoDownload) DownloadHFContext(ctx context.Context, repo string, opt *Options) error
- func (gd *GoDownload) DownloadHFResult(ctx context.Context, repo string, opt *Options) ([]Result, error)
- func (gd *GoDownload) DownloadMany(items []*Options) error
- func (gd *GoDownload) DownloadManyContext(ctx context.Context, items []*Options) error
- func (gd *GoDownload) DownloadManyResult(ctx context.Context, items []*Options) ([]Result, error)
- func (gd *GoDownload) DownloadManySimple(items []string) error
- func (gd *GoDownload) DownloadManySimpleContext(ctx context.Context, items []string) error
- func (gd *GoDownload) DownloadManySimpleResult(ctx context.Context, items []string) ([]Result, error)
- func (gd *GoDownload) DownloadResult(ctx context.Context, path string, opt *Options) (Result, error)
- func (gd *GoDownload) FromFile(path string) error
- func (gd *GoDownload) FromFileContext(ctx context.Context, path string) error
- func (gd *GoDownload) FromFileResult(ctx context.Context, path string) ([]Result, error)
- func (gd *GoDownload) FromManifest(manifestpath string) error
- func (gd *GoDownload) FromManifestContext(ctx context.Context, manifestpath string) error
- func (gd *GoDownload) FromManifestResult(ctx context.Context, manifestpath string) ([]Result, error)
- type ManifestItem
- type Options
- type Result
Constants ¶
const Version = "2.1.1"
Version is the version of the library.
Variables ¶
var ErrChecksumMismatch = errors.New("checksum mismatch")
ErrChecksumMismatch is returned when the downloaded file does not match the expected checksum
var ErrEmptyOutpath = errors.New("outpath is not specified")
ErrEmptyOutpath — ошибка, когда для скачивания страницы не задан путь вывода.
var ErrFileExists = errors.New("file already exists")
ErrFileExists — ошибка, когда целевой файл уже существует, а перезапись запрещена.
var ErrNoRangeSupport = errors.New("server does not support range requests")
ErrNoRangeSupport is returned when Segments > 1 but the server does not support Range requests
var ErrUnsupportedArchive = errors.New("unsupported archive format")
ErrUnsupportedArchive — ошибка неподдерживаемого формата архива.
Functions ¶
This section is empty.
Types ¶
type GoDownload ¶
type GoDownload struct {
//Overwrite provides overwriting file with same name
Overwrite bool
//Alwaysnew provides always creating new file.
// If file with same name exist, create "file_1"
Alwaysnew bool
//UserAgent provides setting user agent for http request
UserAgent string
//Retry provides number of attempts to download file
Retry int
//Authentication before downloading. Auth in the format username:password
Auth string
//Specify archive format for downloaded file.
// Supported values: "zip"
Archive string
//OnProgress is called periodically during the download with
// the number of bytes transferred so far and the total size
// (0 if the total size is unknown, e.g. chunked responses).
// Called from the download goroutine; must be cheap or spawn
// its own goroutine
OnProgress func(transferred, total int64)
//Checksum verifies the downloaded file before it becomes visible.
// Format: "<algorithm>:<hex>", supported algorithms: md5, sha1,
// sha256, sha512. Example: "sha256:abc123..."
// An empty value disables verification
Checksum string
//RateLimit caps the download speed in bytes per second.
// Zero means unlimited
RateLimit int64
//Segments splits large downloads into this many parallel ranged
// segments (only when the server supports Range requests).
// Values < 2 mean a single stream. Default: 1
Segments int
//Path to the config file
Configpath string
//Directory for downloaded files
Outdir string
//Timeout limits the time for the whole request.
// Zero means no timeout (not recommended)
Timeout time.Duration
//Logger is used for all messages of the library.
// nil means log.Default()
Logger *log.Logger
//Quiet disables all logging output
Quiet bool
//HTTPClient allows to provide a custom http.Client.
// If nil, a client with Timeout is used
HTTPClient *http.Client
//NoStale skips the download when the server reports the file
// unchanged since the last download of the same output file
// (conditional request with If-None-Match / If-Modified-Since
// based on a sidecar "<outpath>.gd-meta" file). The Result has
// CacheHit set and Bytes of zero
NoStale bool
//OnDone is called once per successfully downloaded file
// with the outcome of the download (path, size, duration, ...)
// It is the same Result that the *Result methods return
OnDone func(Result)
}
GoDownload provides main struct for global config and downloading items
func (*GoDownload) Download ¶
func (gd *GoDownload) Download(path string, opt *Options) error
Download provides downloading of file from path. Instead of terminating the process on error, it returns an error
func (*GoDownload) DownloadContext ¶
DownloadContext downloads a file from path, honouring ctx cancellation: in-flight HTTP requests are aborted and no file is written after the context is done
func (*GoDownload) DownloadHF ¶
func (gd *GoDownload) DownloadHF(repo string, opt *Options) error
DownloadHF downloads all files of a HuggingFace model repository (https://huggingface.co/<owner>/<name>). Nested paths inside the repository are preserved. The repository files are downloaded concurrently with the global options applied to every file
func (*GoDownload) DownloadHFContext ¶
DownloadHFContext is the context-aware version of DownloadHF
func (*GoDownload) DownloadHFResult ¶
func (gd *GoDownload) DownloadHFResult(ctx context.Context, repo string, opt *Options) ([]Result, error)
DownloadHFResult is the context-aware DownloadHF reporting results. On partial failure it returns the results of the successful downloads together with the aggregated error
func (*GoDownload) DownloadMany ¶
func (gd *GoDownload) DownloadMany(items []*Options) error
DownloadMany provides downloading several files concurrently. Errors of individual downloads are collected and returned as a single aggregated error
func (*GoDownload) DownloadManyContext ¶
func (gd *GoDownload) DownloadManyContext(ctx context.Context, items []*Options) error
DownloadManyContext downloads several files concurrently, honouring ctx cancellation
func (*GoDownload) DownloadManyResult ¶
DownloadManyResult is the context-aware DownloadMany reporting results. On partial failure it returns the results of the successful downloads together with the aggregated error
func (*GoDownload) DownloadManySimple ¶
func (gd *GoDownload) DownloadManySimple(items []string) error
DownloadManySimple is identical for DownloadMany, but as arguments is slice of url
func (*GoDownload) DownloadManySimpleContext ¶
func (gd *GoDownload) DownloadManySimpleContext(ctx context.Context, items []string) error
DownloadManySimpleContext is the context-aware version of DownloadManySimple
func (*GoDownload) DownloadManySimpleResult ¶
func (gd *GoDownload) DownloadManySimpleResult(ctx context.Context, items []string) ([]Result, error)
DownloadManySimpleResult is the context-aware DownloadManySimple reporting results
func (*GoDownload) DownloadResult ¶
func (gd *GoDownload) DownloadResult(ctx context.Context, path string, opt *Options) (Result, error)
DownloadResult is the context-aware download that reports the outcome
func (*GoDownload) FromFile ¶
func (gd *GoDownload) FromFile(path string) error
FromFile provides getting links from file and downloading
func (*GoDownload) FromFileContext ¶
func (gd *GoDownload) FromFileContext(ctx context.Context, path string) error
FromFileContext is the context-aware version of FromFile
func (*GoDownload) FromFileResult ¶
FromFileResult is the context-aware FromFile reporting results
func (*GoDownload) FromManifest ¶
func (gd *GoDownload) FromManifest(manifestpath string) error
FromManifest downloads all files declared in a YAML manifest:
- url: https://example.com/model.bin out: model.bin checksum: sha256:abc... mirrors:
- https://mirror.example.com/model.bin
Items are downloaded concurrently; per-item settings override the global GoDownload config
func (*GoDownload) FromManifestContext ¶
func (gd *GoDownload) FromManifestContext(ctx context.Context, manifestpath string) error
FromManifestContext is the context-aware version of FromManifest
func (*GoDownload) FromManifestResult ¶
func (gd *GoDownload) FromManifestResult(ctx context.Context, manifestpath string) ([]Result, error)
FromManifestResult is the context-aware FromManifest reporting results. On partial failure it returns the results of the successful downloads together with the aggregated error
type ManifestItem ¶
type ManifestItem struct {
// URL of the file to download (required)
URL string `yaml:"url"`
// Out is the output path of the downloaded file (required)
Out string `yaml:"out"`
// Checksum in the "<algorithm>:<hex>" format (optional)
Checksum string `yaml:"checksum,omitempty"`
// Mirrors is a list of alternative URLs (optional).
// The first URL that responds is used; the primary URL
// comes first implicitly
Mirrors []string `yaml:"mirrors,omitempty"`
// Retry overrides the global retry count (optional)
Retry int `yaml:"retry,omitempty"`
// Segments overrides the global segment count (optional)
Segments int `yaml:"segments,omitempty"`
// RateLimit overrides the global rate limit (optional)
RateLimit int64 `yaml:"rate_limit,omitempty"`
// Archive overrides the global archive format (optional)
Archive string `yaml:"archive,omitempty"`
// Auth overrides the global auth (optional)
Auth string `yaml:"auth,omitempty"`
}
ManifestItem describes a single download entry in a YAML manifest
type Options ¶
type Options struct {
// URL parameter needs only for DownloadMany.
// In the case with Download. This parameter will be ignored
URL string
//Download web page instead file
Page bool
//Outpath sets the path of the downloaded file
Outpath string
//Overwrite provides overwriting file with same name
Overwrite bool
//Alwaysnew provides always creating new file.
// If file with same name exist, create "file_1"
Alwaysnew bool
//UserAgent provides setting user agent for http request
UserAgent string
//Retry provides number of attempts to download file
Retry int
//Authentication before downloading. Auth in the format username:password
Auth string
//Specify archive format for downloaded file.
// Supported values: "zip"
Archive string
//OnProgress is called periodically during the download with
// the number of bytes transferred so far and the total size
// (0 if the total size is unknown, e.g. chunked responses).
// Called from the download goroutine; must be cheap or spawn
// its own goroutine
OnProgress func(transferred, total int64)
//Checksum verifies the downloaded file before it becomes visible.
// Format: "<algorithm>:<hex>", supported algorithms: md5, sha1,
// sha256, sha512. Example: "sha256:abc123..."
// An empty value disables verification
Checksum string
//RateLimit caps the download speed in bytes per second.
// Zero means unlimited
RateLimit int64
//Segments splits large downloads into this many parallel ranged
// segments (only when the server supports Range requests).
// Values < 2 mean a single stream. Default: 1
Segments int
//OnDone is called once per successfully downloaded file
// with the outcome of the download (path, size, duration, ...)
// It overrides GoDownload.OnDone for this download
OnDone func(Result)
//NoStale skips the download when the server reports the file
// unchanged since the last download of the same output file.
// It overrides GoDownload.NoStale for this download
NoStale bool
//HFAPIURL overrides the HuggingFace base URL for DownloadHF
// (self-hosted deployments, tests). Empty means
// https://huggingface.co
HFAPIURL string
// contains filtered or unexported fields
}
Options defines attributes for config of GoDownload
type Result ¶
type Result struct {
// URL is the source the file was downloaded from.
// For manifest and mirror downloads it is the URL that
// actually responded successfully
URL string `json:"url"`
// Path is the final path of the downloaded file.
// For archived downloads this is the path of the archive
Path string `json:"path"`
// Size is the size of the final file on disk.
// 0 is reported when the size cannot be determined
Size int64 `json:"size"`
// Bytes is the number of bytes transferred over the network.
// For resumed downloads it may be less than Size
Bytes int64 `json:"bytes"`
// Segments is the number of parallel segments used.
// 1 means a single-stream download
Segments int `json:"segments"`
// ChecksumVerified is true when a checksum was requested
// (Options.Checksum) and the downloaded file passed verification
ChecksumVerified bool `json:"checksum_verified"`
// CacheHit is true when the download was skipped because the
// server reported the file unchanged since the last download
// (Options.NoStale). Bytes is 0 and Size is the size of the
// already existing file
CacheHit bool `json:"cache_hit"`
// Duration is the wall time the download took
Duration time.Duration `json:"duration_ns"`
}
Result describes the outcome of a single completed download. It is returned by the *Result methods and passed to OnDone
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
godownload
command
Command godownload downloads files from URLs or YAML manifests.
|
Command godownload downloads files from URLs or YAML manifests. |
|
examples
|
|
|
basic
command
Basic example: download a file with the default settings.
|
Basic example: download a file with the default settings. |
|
manifest
command
Manifest example: declarative downloads from a YAML file.
|
Manifest example: declarative downloads from a YAML file. |
|
multi-segment
command
Multi-segment example: fast parallel download with progress, throttling and checksum verification.
|
Multi-segment example: fast parallel download with progress, throttling and checksum verification. |
|
rate-limit
command
Rate limit example: throttle the download speed.
|
Rate limit example: throttle the download speed. |
|
internal
|
|
|
clitest
Package clitest provides helpers for testing the example and CLI binaries of the module.
|
Package clitest provides helpers for testing the example and CLI binaries of the module. |