Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A download manager package for Go

License

NotificationsYou must be signed in to change notification settings

floeit/grab

 
 

Repository files navigation

GoDocBuild StatusGo Report Card

Downloading the internet, one goroutine at a time!

$ go get github.com/cavaliercoder/grab

Grab is a Go package for downloading files from the internet with the followingrad features:

  • Monitor download progress concurrently
  • Auto-resume incomplete downloads
  • Guess filename from content header or URL path
  • Safely cancel downloads using context.Context
  • Validate downloads using checksums
  • Download batches of files concurrently

Requires Go v1.7+

Older versions

If you are using an older version of Go, or require previous versions of theGrab API, you can import older version of this package, thanks to gpkg.in.Please see all GitHub tags for available versions.

$ go get gopkg.in/cavaliercoder/grab.v1

Example

The following example downloads a PDF copy of the free eBook, "An Introductionto Programming in Go" and periodically prints the download progress until it iscomplete.

The second time you run the example, it will auto-resume the previous downloadand exit sooner.

package mainimport ("fmt""os""time""github.com/cavaliercoder/grab")funcmain() {// create clientclient:=grab.NewClient()req,_:=grab.NewRequest(".","http://www.golang-book.com/public/pdf/gobook.pdf")// start downloadfmt.Printf("Downloading %v...\n",req.URL())resp:=client.Do(req)fmt.Printf("  %v\n",resp.HTTPResponse.Status)// start UI loopt:=time.NewTicker(500*time.Millisecond)defert.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 completebreak Loop}}// check for errorsiferr:=resp.Err();err!=nil {fmt.Fprintf(os.Stderr,"Download failed: %v\n",err)os.Exit(1)}fmt.Printf("Download saved to ./%v\n",resp.Filename)// Output:// Downloading http://www.golang-book.com/public/pdf/gobook.pdf...//   200 OK//   transferred 42970 / 2893557 bytes (1.49%)//   transferred 1207474 / 2893557 bytes (41.73%)//   transferred 2758210 / 2893557 bytes (95.32%)// Download saved to ./gobook.pdf}

About

A download manager package for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go99.0%
  • Makefile1.0%

[8]ページ先頭

©2009-2025 Movatter.jp