Skip to content

Commit

Permalink
Merge pull request #4 from joeybloggs/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
deankarn committed May 27, 2017
2 parents c6c9e76 + b27d0e3 commit 7a84e61
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 111 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package go-download
===================
![Project status](https://img.shields.io/badge/version-1.0.0-green.svg)
![Project status](https://img.shields.io/badge/version-2.0.0-green.svg)
[![Build Status](https://travis-ci.org/joeybloggs/go-download.svg?branch=master)](https://travis-ci.org/joeybloggs/go-download)
[![Coverage Status](https://coveralls.io/repos/github/joeybloggs/go-download/badge.svg?branch=master)](https://coveralls.io/github/joeybloggs/go-download?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/joeybloggs/go-download)](https://goreportcard.com/report/github.com/joeybloggs/go-download)
Expand All @@ -20,7 +20,7 @@ go get -u github.com/joeybloggs/go-download

## Examples

More examples [here](https://github.com/joeybloggs/go-download/tree/master/examples)
More examples [here](https://github.com/joeybloggs/go-download/tree/master/_examples)

```go
package main
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"
"log"

Expand All @@ -14,9 +15,9 @@ func main() {
defer progress.Stop()

options := &download.Options{
Proxy: func(name string, size int64, r io.Reader) io.Reader {
Proxy: func(name string, download int, size int64, r io.Reader) io.Reader {
bar := progress.AddBar(size).
PrependName(name, 0, 0).
PrependName(fmt.Sprintf("%s-%d", name, download), 0, 0).
PrependCounters("%3s / %3s", mpb.UnitBytes, 18, mpb.DwidthSync|mpb.DextraSpace).
AppendPercentage(5, 0)

Expand Down
35 changes: 35 additions & 0 deletions cmd/goget/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"io"
"log"

download "github.com/joeybloggs/go-download"
"github.com/vbauerster/mpb"
)

func main() {

progress := mpb.New().SetWidth(80)
defer progress.Stop()

options := &download.Options{
Proxy: func(name string, download int, size int64, r io.Reader) io.Reader {
bar := progress.AddBar(size).
PrependName(fmt.Sprintf("%s-%d", name, download), 0, 0).
PrependCounters("%3s / %3s", mpb.UnitBytes, 18, mpb.DwidthSync|mpb.DextraSpace).
AppendPercentage(5, 0)

return bar.ProxyReader(r)
},
}

f, err := download.Open("https://storage.googleapis.com/golang/go1.8.1.src.tar.gz", options)
if err != nil {
log.Fatal(err)
}
defer f.Close()

// f implements io.Reader, write file somewhere or do some other sort of work with it
}
Loading

0 comments on commit 7a84e61

Please sign in to comment.