|
|
@ -7,7 +7,7 @@ import ( |
|
|
|
|
|
|
|
type SReadCloser struct { |
|
|
|
r io.Reader |
|
|
|
bytes int |
|
|
|
Bytes int |
|
|
|
start time.Time |
|
|
|
lastCalc time.Time |
|
|
|
speed int |
|
|
@ -15,7 +15,7 @@ type SReadCloser struct { |
|
|
|
|
|
|
|
func (s *SReadCloser) Read(data []byte) (n int, err error) { |
|
|
|
n, err = s.r.Read(data) |
|
|
|
s.bytes += n |
|
|
|
s.Bytes += n |
|
|
|
now := time.Now() |
|
|
|
elapsed := now.Sub(s.lastCalc).Seconds() |
|
|
|
if elapsed >= 1 { |
|
|
@ -30,7 +30,7 @@ func (s *SReadCloser) Speed() int { |
|
|
|
} |
|
|
|
|
|
|
|
func (s *SReadCloser) Average() float64 { |
|
|
|
return float64(s.bytes) / s.start.Sub(s.lastCalc).Seconds() |
|
|
|
return float64(s.Bytes) / s.start.Sub(s.lastCalc).Seconds() |
|
|
|
} |
|
|
|
|
|
|
|
func (s *SReadCloser) Bind(r io.Reader) io.Reader { |
|
|
|