package iox import ( "io" "time" ) type WriteProgressFunc func(sofar int64) type WriteProgress struct { WriteTo io.Writer last time.Time count int64 Progress WriteProgressFunc } func (wc *WriteProgress) Done() { wc.Progress(wc.count) } func (wc *WriteProgress) Write(p []byte) (int, error) { wc.count += int64(len(p)) now := time.Now() if now.Sub(wc.last) > time.Duration(time.Second*1) { wc.last = now wc.Progress(wc.count) } return wc.WriteTo.Write(p) }