@@ -23,6 +23,7 @@ import (
23
23
"github.com/arduino/arduino-cli/arduino"
24
24
"github.com/arduino/arduino-cli/configuration"
25
25
"github.com/arduino/arduino-cli/i18n"
26
+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
26
27
"github.com/arduino/go-paths-helper"
27
28
"go.bug.st/downloader/v2"
28
29
)
@@ -31,7 +32,7 @@ var tr = i18n.Tr
31
32
32
33
// DownloadFile downloads a file from a URL into the specified path. An optional config and options may be passed (or nil to use the defaults).
33
34
// A DownloadProgressCB callback function must be passed to monitor download progress.
34
- func DownloadFile (path * paths.Path , URL string , label string , downloadCB DownloadProgressCB , config * downloader.Config , options ... downloader.DownloadOptions ) error {
35
+ func DownloadFile (path * paths.Path , URL string , label string , downloadCB rpc. DownloadProgressCB , config * downloader.Config , options ... downloader.DownloadOptions ) error {
35
36
if config == nil {
36
37
c , err := GetDownloaderConfig ()
37
38
if err != nil {
@@ -44,14 +45,14 @@ func DownloadFile(path *paths.Path, URL string, label string, downloadCB Downloa
44
45
if err != nil {
45
46
return err
46
47
}
47
- downloadCB (& DownloadProgress {
48
+ downloadCB (& rpc. DownloadProgress {
48
49
File : label ,
49
- URL : d .URL ,
50
+ Url : d .URL ,
50
51
TotalSize : d .Size (),
51
52
})
52
53
53
54
err = d .RunAndPoll (func (downloaded int64 ) {
54
- downloadCB (& DownloadProgress {Downloaded : downloaded })
55
+ downloadCB (& rpc. DownloadProgress {Downloaded : downloaded })
55
56
}, 250 * time .Millisecond )
56
57
if err != nil {
57
58
return err
@@ -62,7 +63,7 @@ func DownloadFile(path *paths.Path, URL string, label string, downloadCB Downloa
62
63
return & arduino.FailedDownloadError {Message : tr ("Server responded with: %s" , d .Resp .Status )}
63
64
}
64
65
65
- downloadCB (& DownloadProgress {Completed : true })
66
+ downloadCB (& rpc. DownloadProgress {Completed : true })
66
67
return nil
67
68
}
68
69
@@ -94,24 +95,6 @@ func NewWithConfig(config *Config) *http.Client {
94
95
}
95
96
}
96
97
97
- // DownloadProgress is a report of the download progress, not all fields may be
98
- // filled and multiple reports may be sent during a download.
99
- type DownloadProgress struct {
100
- // URL of the download.
101
- URL string
102
- // The file being downloaded.
103
- File string
104
- // TotalSize is the total size of the file being downloaded.
105
- TotalSize int64
106
- // Downloaded is the size of the downloaded portion of the file.
107
- Downloaded int64
108
- // Completed reports whether the download is complete.
109
- Completed bool
110
- }
111
-
112
- // DownloadProgressCB is a callback function to report download progress
113
- type DownloadProgressCB func (progress * DownloadProgress )
114
-
115
98
// GetDownloaderConfig returns the downloader configuration based on current settings.
116
99
func GetDownloaderConfig () (* downloader.Config , error ) {
117
100
httpClient , err := New ()
0 commit comments