Files
lpm/url/client.go
zeekay 7d7127a687 deps: update to latest luxfi packages
- Update node v1.16.15 → v1.19.8
- Update crypto v1.17.0 → v1.17.4
- Update database v1.2.0 → v1.2.1
- Update geth v1.16.34 → v1.16.35
- Update ids v1.1.0 → v1.1.1
- Update Go 1.25 → 1.25.1
- Update copyright year to 2025
2025-09-30 00:05:18 +00:00

65 lines
1.1 KiB
Go

// Copyright (C) 2019-2025, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package url
import (
"fmt"
"time"
"github.com/cavaliergopher/grab/v3"
)
var _ Client = &client{}
type Client interface {
Download(url string, path string) error
}
func NewClient() Client {
return &client{
grab.NewClient(),
}
}
type client struct {
client *grab.Client
}
func (h client) Download(url string, path string) error {
req, err := grab.NewRequest(path, url)
if err != nil {
return err
}
fmt.Printf("Downloading %v...\n", req.URL())
resp := h.client.Do(req)
fmt.Printf("HTTP response %v\n", resp.HTTPResponse.Status)
// Start progress loop
t := time.NewTicker(1 * time.Second)
defer t.Stop()
Loop:
for {
select {
case <-t.C:
fmt.Printf(" transferred %v / %v bytes (%.2f%%)\n",
resp.BytesComplete(),
resp.Size(),
100*resp.Progress())
case <-resp.Done:
// download is complete
break Loop
}
}
// check for errors
if err := resp.Err(); err != nil {
return fmt.Errorf("Download failed: %s", err)
}
return nil
}