Browse Source

add a lot

master v0.0.39
RealXLFD 2 months ago
parent
commit
f6a225c694
  1. 6
      utils/ioplus/reader.go
  2. 6
      utils/ioplus/writer.go

6
utils/ioplus/reader.go

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

6
utils/ioplus/writer.go

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

Loading…
Cancel
Save