Skip to content

Commit

Permalink
Update standalone
Browse files Browse the repository at this point in the history
Standalone is very rudimentary, but works.
  • Loading branch information
deankarn committed May 29, 2017
1 parent 0fd1169 commit b655936
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ It Features:
```shell
go get -u github.com/joeybloggs/go-download
```
or if your looking for the standalone client
```shell
go get -u github.com/joeybloggs/go-download/cmd/goget
```

## Examples

Expand Down
25 changes: 23 additions & 2 deletions cmd/goget/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import (
"io"
"log"

"os"

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

func main() {

url := os.Args[len(os.Args)-1]

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

Expand All @@ -25,11 +29,28 @@ func main() {
},
}

f, err := download.Open("https://storage.googleapis.com/golang/go1.8.1.src.tar.gz", options)
f, err := download.Open(url, 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
info, err := f.Stat()
if err != nil {
log.Fatal(err)
}

var output *os.File
name := info.Name()
output, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Fatal(err)
}
defer output.Close()

if _, err = io.Copy(output, f); err != nil {
log.Fatal(err)
}

log.Printf("Success. %s saved.", name)
}
2 changes: 1 addition & 1 deletion download.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func OpenContext(ctx context.Context, url string, options *Options) (*File, erro
// not all services support HEAD requests
// so if this fails just move along to the
// GET portion, with a warning
log.Printf("notice: unexpected HEAD response code '%d', proceeding with download.", resp.StatusCode)
log.Printf("notice: unexpected HEAD response code '%d', proceeding with download.\n", resp.StatusCode)
err = f.download(ctx)
} else {
f.size = resp.ContentLength
Expand Down

0 comments on commit b655936

Please sign in to comment.