(contents io.Reader, size uint64, dst string, errOut io.Writer)
| 430 | } |
| 431 | |
| 432 | func copySharedLinkContentToFile(contents io.Reader, size uint64, dst string, errOut io.Writer) error { |
| 433 | if errOut == nil { |
| 434 | errOut = io.Discard |
| 435 | } |
| 436 | |
| 437 | finalDst, err := downloadDestinationPath(dst) |
| 438 | if err != nil { |
| 439 | return err |
| 440 | } |
| 441 | |
| 442 | f, tmp, err := createDownloadTemp(finalDst) |
| 443 | if err != nil { |
| 444 | return err |
| 445 | } |
| 446 | removeTemp := true |
| 447 | defer func() { |
| 448 | if removeTemp { |
| 449 | _ = os.Remove(tmp) |
| 450 | } |
| 451 | }() |
| 452 | |
| 453 | progressbar := &ioprogress.Reader{ |
| 454 | Reader: contents, |
| 455 | DrawFunc: ioprogress.DrawTerminalf(errOut, func(progress, total int64) string { |
| 456 | return fmt.Sprintf("Downloading %s/%s", |
| 457 | humanize.IBytes(uint64(progress)), humanize.IBytes(uint64(total))) |
| 458 | }), |
| 459 | Size: int64(size), |
| 460 | } |
| 461 | |
| 462 | _, copyErr := io.Copy(f, progressbar) |
| 463 | closeErr := f.Close() |
| 464 | if copyErr != nil { |
| 465 | return copyErr |
| 466 | } |
| 467 | if closeErr != nil { |
| 468 | return closeErr |
| 469 | } |
| 470 | if err := os.Rename(tmp, finalDst); err != nil { |
| 471 | return err |
| 472 | } |
| 473 | removeTemp = false |
| 474 | return nil |
| 475 | } |
| 476 | |
| 477 | func sharedLinkDownloadTarget(target string, link sharing.IsSharedLinkMetadata) (string, error) { |
| 478 | name, err := sharedLinkDownloadName(link) |
no test coverage detected