@@ -22,14 +22,17 @@ import (
2222 _ "embed"
2323 "encoding/json"
2424 "fmt"
25+ "io/ioutil"
26+
27+ "compress/gzip"
2528
2629 "github.com/arduino/arduino-cloud-cli/internal/binary/gpgkey"
2730 "golang.org/x/crypto/openpgp"
2831)
2932
3033const (
3134 // URL of cloud-team binary index
32- BinaryIndexURL = "https://cloud-downloads.arduino.cc/binaries/index.json"
35+ BinaryIndexGZURL = "https://cloud-downloads.arduino.cc/binaries/index.json.gz "
3336 // URL of binary index signature
3437 BinaryIndexSigURL = "https://cloud-downloads.arduino.cc/binaries/index.json.sig"
3538)
@@ -56,11 +59,20 @@ type IndexBin struct {
5659// LoadIndex downloads and verify the index of binaries contained
5760// in 'cloud-downloads'
5861func LoadIndex () (* Index , error ) {
59- index , err := download (BinaryIndexURL )
62+ indexGZ , err := download (BinaryIndexGZURL )
6063 if err != nil {
6164 return nil , fmt .Errorf ("cannot download index: %w" , err )
6265 }
6366
67+ indexReader , err := gzip .NewReader (bytes .NewReader (indexGZ ))
68+ if err != nil {
69+ return nil , fmt .Errorf ("cannot decompress index: %w" , err )
70+ }
71+ index , err := ioutil .ReadAll (indexReader )
72+ if err != nil {
73+ return nil , fmt .Errorf ("cannot read downloaded index: %w" , err )
74+ }
75+
6476 sig , err := download (BinaryIndexSigURL )
6577 if err != nil {
6678 return nil , fmt .Errorf ("cannot download index signature: %w" , err )
@@ -73,12 +85,14 @@ func LoadIndex() (*Index, error) {
7385
7486 signer , err := openpgp .CheckDetachedSignature (keyRing , bytes .NewReader (index ), bytes .NewReader (sig ))
7587 if signer == nil || err != nil {
76- return nil , fmt .Errorf ("index at %s not valid" , BinaryIndexURL )
88+ return nil , fmt .Errorf ("index at %s not valid" , BinaryIndexGZURL )
7789 }
7890
7991 i := & Index {}
80- err = json .Unmarshal (index , & i .Boards )
81- return i , err
92+ if err = json .Unmarshal (index , & i .Boards ); err != nil {
93+ return nil , fmt .Errorf ("cannot unmarshal index json: %w" , err )
94+ }
95+ return i , nil
8296}
8397
8498// FindProvisionBin looks for the provisioning binary corresponding
0 commit comments