Skip to content
io.Reader and io.Writer with progress and remaining time estimation
Go
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example/download Improve example Jan 7, 2018
.gitignore Initial commit Dec 31, 2017
.travis.yml simpler Jan 2, 2018
LICENSE Initial commit Dec 31, 2017
README.md updated formatting Jan 8, 2018
progress.go updated example to use `range` Jan 8, 2018
progress_test.go Added Err to counter for deterministic completion Jan 4, 2018
reader.go
reader_test.go fixed missing error check Jan 2, 2018
writer.go Added Err to counter for deterministic completion Jan 4, 2018
writer_test.go simplified interface Jan 2, 2018

README.md

progress GoDoc Build Status Go Report Card

io.Reader and io.Writer with progress and remaining time estimation.

Usage

ctx := context.Background()

// get a reader and the total expected number of bytes
s := `Now that's what I call progress`
size := len(s)
r := progress.NewReader(strings.NewReader(s))

// Start a goroutine printing progress
go func() {
	ctx := context.Background()
	progressChan := progress.NewTicker(ctx, r, size, 1*time.Second)
	for p := range progressChan {
		fmt.Printf("\r%v remaining...", p.Remaining().Round(time.Second))
	}
	fmt.Println("\rdownload is completed")
}()

// use the Reader as normal
if _, err := io.Copy(dest, r); err != nil {
	log.Fatalln(err)
}
  1. Wrap an io.Reader or io.Writer with NewReader and NewWriter respectively
  2. Capture the total number of expected bytes
  3. Use progress.NewTicker to get a channel on which progress updates will be sent
  4. Start a Goroutine to periodically check the progress, and do something with it - like log it
  5. Use the readers and writers as normal
You can’t perform that action at this time.