MCPcopy Create free account
hub / github.com/apecloud/myduckserver / DownloadFile

Method DownloadFile

storage/object_storage.go:59–84  ·  view source on GitHub ↗

DownloadFile downloads a file from the remote storage to the local storage.

(remotePath, localDir, localFile string)

Source from the content-addressed store, hash-verified

57
58// DownloadFile downloads a file from the remote storage to the local storage.
59func (storageConfig *ObjectStorageConfig) DownloadFile(remotePath, localDir, localFile string) (string, error) {
60 startMillis := time.Now().UnixMilli()
61 localFullPath := path.Join(localDir, localFile)
62 s3Cfg, err := storageConfig.buildConfig()
63 if err != nil {
64 return "", err
65 }
66
67 // Parse the bucket and key from the remote path
68 bucket, key := parseBucketAndPath(remotePath)
69 if strings.HasSuffix(key, "/") {
70 key += localFile
71 }
72
73 bucketBasics := NewBucket(s3Cfg)
74
75 size, err := bucketBasics.DownloadFile(context.TODO(), bucket, key, localFullPath)
76 if err != nil {
77 return "", err
78 }
79
80 timeCost := time.Now().UnixMilli() - startMillis
81 return fmt.Sprintf("Downloaded from %s://%s/%s (%d bytes) to %s in %d ms\n",
82 storageConfig.Provider, bucket, key, size, localFullPath, timeCost), nil
83
84}
85
86func (storageConfig *ObjectStorageConfig) buildConfig() (cfg *aws.Config, err error) {
87 var s3Cfg aws.Config

Callers

nothing calls this directly

Calls 4

buildConfigMethod · 0.95
DownloadFileMethod · 0.95
parseBucketAndPathFunction · 0.85
NewBucketFunction · 0.85

Tested by

no test coverage detected