@@ -23,6 +23,7 @@ import (
2323 "github.com/arduino/arduino-cli/arduino"
2424 "github.com/arduino/arduino-cli/configuration"
2525 "github.com/arduino/arduino-cli/i18n"
26+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2627 "github.com/arduino/go-paths-helper"
2728 "go.bug.st/downloader/v2"
2829)
@@ -31,7 +32,7 @@ var tr = i18n.Tr
3132
3233// 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).
3334// 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 {
3536 if config == nil {
3637 c , err := GetDownloaderConfig ()
3738 if err != nil {
@@ -44,14 +45,14 @@ func DownloadFile(path *paths.Path, URL string, label string, downloadCB Downloa
4445 if err != nil {
4546 return err
4647 }
47- downloadCB (& DownloadProgress {
48+ downloadCB (& rpc. DownloadProgress {
4849 File : label ,
49- URL : d .URL ,
50+ Url : d .URL ,
5051 TotalSize : d .Size (),
5152 })
5253
5354 err = d .RunAndPoll (func (downloaded int64 ) {
54- downloadCB (& DownloadProgress {Downloaded : downloaded })
55+ downloadCB (& rpc. DownloadProgress {Downloaded : downloaded })
5556 }, 250 * time .Millisecond )
5657 if err != nil {
5758 return err
@@ -62,7 +63,7 @@ func DownloadFile(path *paths.Path, URL string, label string, downloadCB Downloa
6263 return & arduino.FailedDownloadError {Message : tr ("Server responded with: %s" , d .Resp .Status )}
6364 }
6465
65- downloadCB (& DownloadProgress {Completed : true })
66+ downloadCB (& rpc. DownloadProgress {Completed : true })
6667 return nil
6768}
6869
@@ -94,24 +95,6 @@ func NewWithConfig(config *Config) *http.Client {
9495 }
9596}
9697
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-
11598// GetDownloaderConfig returns the downloader configuration based on current settings.
11699func GetDownloaderConfig () (* downloader.Config , error ) {
117100 httpClient , err := New ()
0 commit comments