DownloadFile downloads a file from the remote storage to the local storage.
(remotePath, localDir, localFile string)
| 57 | |
| 58 | // DownloadFile downloads a file from the remote storage to the local storage. |
| 59 | func (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 | |
| 86 | func (storageConfig *ObjectStorageConfig) buildConfig() (cfg *aws.Config, err error) { |
| 87 | var s3Cfg aws.Config |
nothing calls this directly
no test coverage detected