gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/uio/progress.go (about) 1 // Copyright 2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package uio 6 7 import ( 8 "io" 9 "strings" 10 ) 11 12 // ProgressReader implements io.Reader and prints Symbol to W after every 13 // Interval bytes passes through R. 14 type ProgressReader struct { 15 R io.Reader 16 17 Symbol string 18 Interval int 19 W io.Writer 20 21 counter int 22 } 23 24 // Read implements io.Reader for ProgressReader. 25 func (r *ProgressReader) Read(p []byte) (n int, err error) { 26 defer func() { 27 //log.Print("r.Counter %d, r.Interval %d, n 28 numSymbols := (r.counter%r.Interval + n) / r.Interval 29 r.W.Write([]byte(strings.Repeat(r.Symbol, numSymbols))) 30 r.counter += n 31 }() 32 return r.R.Read(p) 33 }