MCPcopy Create free account
hub / github.com/dropbox/dbxcli / copySharedLinkContentToFile

Function copySharedLinkContentToFile

cmd/share_link_download.go:432–475  ·  view source on GitHub ↗
(contents io.Reader, size uint64, dst string, errOut io.Writer)

Source from the content-addressed store, hash-verified

430}
431
432func 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
477func sharedLinkDownloadTarget(target string, link sharing.IsSharedLinkMetadata) (string, error) {
478 name, err := sharedLinkDownloadName(link)

Callers 2

downloadSharedLinkToFileFunction · 0.85

Calls 4

downloadDestinationPathFunction · 0.85
createDownloadTempFunction · 0.85
CopyMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected