@ -3,6 +3,8 @@ package updater
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
// LimitReachedError records the limit and the operation that caused it.
|
||||
@ -33,7 +35,7 @@ func (lr *limitedReader) Read(p []byte) (n int, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
p = p[:min(lr.n, int64(len(p)))]
|
||||
p = p[:Min(lr.n, int64(len(p)))]
|
||||
|
||||
n, err = lr.r.Read(p)
|
||||
lr.n -= int64(n)
|
||||
@ -54,3 +56,12 @@ func LimitReader(r io.Reader, n int64) (limited io.Reader, err error) {
|
||||
n: n,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Min returns the smaller of x or y.
|
||||
func Min[T constraints.Integer | ~string](x, y T) (res T) {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
Reference in New Issue
Block a user