Skip to content

Commit 5bb8135

Browse files
committed
Use a variable to track current reader position
... instead of using `math.Mod`
1 parent 6b0fcc5 commit 5bb8135

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

defs/bytes_counter.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"fmt"
77
"io"
88
"log"
9-
"math"
109
"sync"
1110
"time"
1211
)
1312

1413
// BytesCounter implements io.Reader and io.Writer interface, for counting bytes being read/written in HTTP requests
1514
type BytesCounter struct {
1615
start time.Time
16+
pos int
1717
total int
1818
payload []byte
1919
reader io.ReadSeeker
@@ -43,8 +43,9 @@ func (c *BytesCounter) Read(p []byte) (int, error) {
4343
n, err := c.reader.Read(p)
4444
c.lock.Lock()
4545
c.total += n
46-
47-
if math.Mod(float64(c.total), uploadSize) == 0 {
46+
c.pos += n
47+
if c.pos == uploadSize {
48+
c.pos = 0
4849
c.resetReader()
4950
}
5051
c.lock.Unlock()

0 commit comments

Comments
 (0)