k3s/vendor/github.com/lxc/lxd/shared/ioprogress/writer.go

26 lines
503 B
Go
Raw Normal View History

2019-11-08 21:45:10 +00:00
package ioprogress
import (
"io"
)
// ProgressWriter is a wrapper around WriteCloser which allows for progress tracking
type ProgressWriter struct {
io.WriteCloser
Tracker *ProgressTracker
}
// Write in ProgressWriter is the same as io.Write
func (pt *ProgressWriter) Write(p []byte) (int, error) {
// Do normal writer tasks
n, err := pt.WriteCloser.Write(p)
// Do the actual progress tracking
if pt.Tracker != nil {
pt.Tracker.total += int64(n)
pt.Tracker.update(n)
}
return n, err
}