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

Function downloadFileOnce

cmd/get.go:437–482  ·  view source on GitHub ↗
(dbx filesClient, arg *files.DownloadArg, dst string, errOut io.Writer)

Source from the content-addressed store, hash-verified

435}
436
437func downloadFileOnce(dbx filesClient, arg *files.DownloadArg, dst string, errOut io.Writer) (*files.FileMetadata, error) {
438 res, contents, err := dbx.DownloadContext(currentContext(), arg)
439 if err != nil {
440 return nil, err
441 }
442 defer func() { _ = contents.Close() }()
443
444 finalDst, err := downloadDestinationPath(dst)
445 if err != nil {
446 return nil, err
447 }
448
449 f, tmp, err := createDownloadTemp(finalDst)
450 if err != nil {
451 return nil, err
452 }
453 removeTemp := true
454 defer func() {
455 if removeTemp {
456 _ = os.Remove(tmp)
457 }
458 }()
459
460 progressbar := &ioprogress.Reader{
461 Reader: contents,
462 DrawFunc: ioprogress.DrawTerminalf(errOut, func(progress, total int64) string {
463 return fmt.Sprintf("Downloading %s/%s",
464 humanize.IBytes(uint64(progress)), humanize.IBytes(uint64(total)))
465 }),
466 Size: downloadMetadataSize(res),
467 }
468
469 _, copyErr := io.Copy(f, progressbar)
470 closeErr := f.Close()
471 if copyErr != nil {
472 return nil, copyErr
473 }
474 if closeErr != nil {
475 return nil, closeErr
476 }
477 if err := os.Rename(tmp, finalDst); err != nil {
478 return nil, err
479 }
480 removeTemp = false
481 return res, nil
482}
483
484func downloadMetadataSize(metadata *files.FileMetadata) int64 {
485 if metadata == nil {

Callers 1

downloadFileWithMetadataFunction · 0.85

Calls 7

currentContextFunction · 0.85
downloadDestinationPathFunction · 0.85
createDownloadTempFunction · 0.85
downloadMetadataSizeFunction · 0.85
CloseMethod · 0.80
CopyMethod · 0.80
DownloadContextMethod · 0.65

Tested by

no test coverage detected