Skip to content

Commit

Permalink
Switch to pb for upload progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantmonkey committed Dec 18, 2018
1 parent a54182d commit 51b91a6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions linx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

"github.com/adrg/xdg"
"golang.org/x/net/proxy"
"gopkg.in/cheggaaa/pb.v1"
"gopkg.in/yaml.v2"
"mutantmonkey.in/code/golinx/progress"
)

type Config struct {
Expand Down Expand Up @@ -82,7 +82,13 @@ func prepareProxyClient(proxyUrl string) *http.Client {

func linx(config *Config, filename string, size int64, f io.Reader, ttl int, deleteKey string) (data LinxJSON, err error) {
client := prepareProxyClient(config.Proxy)
reader := progress.NewProgressReader(filename, bufio.NewReader(f), size)

bar := pb.New(int(size))
bar.SetUnits(pb.U_BYTES)
bar.Prefix(fmt.Sprintf("%.20s ", filename))
bar.Start()

reader := bar.NewProxyReader(bufio.NewReader(f))

req, err := http.NewRequest("PUT", config.Server+"upload/"+filename, reader)
if err != nil {
Expand All @@ -109,6 +115,8 @@ func linx(config *Config, filename string, size int64, f io.Reader, ttl int, del
}
defer resp.Body.Close()

bar.Finish()

if resp.StatusCode != 200 {
err = fmt.Errorf("Upload failed: %s", resp.Status)
return
Expand Down

0 comments on commit 51b91a6

Please sign in to comment.