getZsyncControlFile wraps zsync.GetControlFile giving the option to use a local file instead of fetching remotely.
(client zsync.HTTPRequester, source, keepZsync, referer string)
| 286 | // getZsyncControlFile wraps zsync.GetControlFile giving the option to use a |
| 287 | // local file instead of fetching remotely. |
| 288 | func getZsyncControlFile(client zsync.HTTPRequester, source, keepZsync, referer string) (io.ReadCloser, string, error) { |
| 289 | // First try to read from local file. |
| 290 | if _, err := os.Stat(source); err == nil { |
| 291 | f, err := os.Open(source) |
| 292 | if err != nil { |
| 293 | return nil, "", fmt.Errorf("failed to open .zsync: %w", err) |
| 294 | } |
| 295 | // If the control file is local, we use the supplied referer URL as the |
| 296 | // referer for the target file requests. |
| 297 | return f, referer, nil |
| 298 | } |
| 299 | |
| 300 | return zsync.GetControlFile(client, source, keepZsync, referer) |
| 301 | } |
| 302 | |
| 303 | func readSeedFile(zs *zsync.Syncer, filename string, noProgress bool) error { |
| 304 | if !noProgress { |
no test coverage detected