Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philandstuff committed Mar 6, 2024
1 parent 16a1ce4 commit e64f063
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/download/buffered_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type bufferedReader struct {

var _ io.Reader = &bufferedReader{}

var emptyBuffer = bytes.NewBuffer(nil)

func newBufferedReader(pool *bufferPool) *bufferedReader {
return &bufferedReader{
ready: make(chan struct{}),
Expand All @@ -39,12 +41,12 @@ func (b *bufferedReader) Read(buf []byte) (int, error) {
}
n, err := b.buf.Read(buf)
// If we've read all the data,
if b.buf.Len() == 0 {
// replace our buffer with something that will always return EOF on
// future reads
b.buf = bytes.NewBuffer(nil)
// and return the buffer to the pool
if b.buf.Len() == 0 && b.buf != emptyBuffer {
// return the buffer to the pool
b.pool.Put(b.buf)
// and replace our buffer with something that will always return EOF on
// future reads
b.buf = emptyBuffer
}
return n, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/download/consistent_hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func GetConsistentHashingMode(opts Options) (*ConsistentHashingMode, error) {
queue: queue,
}
m.pool = newBufferPool(m.chunkSize())
fallbackStrategy.pool = m.pool
return m, nil
}

Expand Down

0 comments on commit e64f063

Please sign in to comment.