Removed unused utility future.Pv()
This commit is contained in:
parent
0208b6accd
commit
deb603aaf4
1 changed files with 1 additions and 27 deletions
|
@ -1,9 +1,6 @@
|
|||
package future
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
import ()
|
||||
|
||||
func Go(f func() error) chan error {
|
||||
ch := make(chan error)
|
||||
|
@ -12,26 +9,3 @@ func Go(f func() error) chan error {
|
|||
}()
|
||||
return ch
|
||||
}
|
||||
|
||||
// Pv wraps an io.Reader such that it is passed through unchanged,
|
||||
// but logs the number of bytes copied (comparable to the unix command pv)
|
||||
func Pv(src io.Reader, info io.Writer) io.Reader {
|
||||
var totalBytes int
|
||||
data := make([]byte, 2048)
|
||||
r, w := io.Pipe()
|
||||
go func() {
|
||||
for {
|
||||
if n, err := src.Read(data); err != nil {
|
||||
w.CloseWithError(err)
|
||||
return
|
||||
} else {
|
||||
totalBytes += n
|
||||
fmt.Fprintf(info, "--> %d bytes\n", totalBytes)
|
||||
if _, err = w.Write(data[:n]); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return r
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue