MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / Download

Method Download

internal/net/request.go:75–100  ·  view source on GitHub ↗

Download The Downloader makes multi-thread http requests to remote URL, each chunk(except last one) has PartSize, cache some data, then return Reader with assembled data Supports range, do not support unknown FileSize, and will fail if FileSize is incorrect memory usage is at about Concurrency*PartS

(ctx context.Context, p *HttpRequestParams)

Source from the content-addressed store, hash-verified

73// Supports range, do not support unknown FileSize, and will fail if FileSize is incorrect
74// memory usage is at about Concurrency*PartSize, use this wisely
75func (d Downloader) Download(ctx context.Context, p *HttpRequestParams) (readCloser io.ReadCloser, err error) {
76
77 var finalP HttpRequestParams
78 awsutil.Copy(&finalP, p)
79 if finalP.Range.Length < 0 || finalP.Range.Start+finalP.Range.Length > finalP.Size {
80 finalP.Range.Length = finalP.Size - finalP.Range.Start
81 }
82 impl := downloader{params: &finalP, cfg: d, ctx: ctx}
83
84 // Ensures we don't need nil checks later on
85 // 必需的选项
86 if impl.cfg.Concurrency == 0 {
87 impl.cfg.Concurrency = DefaultDownloadConcurrency
88 }
89 if impl.cfg.PartSize == 0 {
90 impl.cfg.PartSize = DefaultDownloadPartSize
91 }
92 if conf.MinFreeMemory > 0 && impl.cfg.PartSize > int(conf.MaxBlockLimit) {
93 impl.cfg.PartSize = int(conf.MaxBlockLimit)
94 }
95 if impl.cfg.HttpClient == nil {
96 impl.cfg.HttpClient = DefaultHttpRequestFunc
97 }
98
99 return impl.download()
100}
101
102// downloader is the implementation structure used internally by Downloader.
103type downloader struct {

Callers 5

TestDownloadOrderFunction · 0.95
TestDownloadInterruptFunction · 0.95
TestHighConcurrencyFunction · 0.95
TestDownloadSingleFunction · 0.95
GetRangeReaderFromLinkFunction · 0.95

Calls 2

downloadMethod · 0.95
CopyMethod · 0.65

Tested by 4

TestDownloadOrderFunction · 0.76
TestDownloadInterruptFunction · 0.76
TestHighConcurrencyFunction · 0.76
TestDownloadSingleFunction · 0.76