avoid sendFile() for ranges or object lengths < 4MiB (#20141)

This commit is contained in:
Harshavardhana
2024-07-24 03:22:50 -07:00
committed by GitHub
parent b368d4cc13
commit 6fe2b3f901
3 changed files with 34 additions and 32 deletions

View File

@@ -243,6 +243,15 @@ func NopCloser(w io.Writer) io.WriteCloser {
return nopCloser{w}
}
const copyBufferSize = 32 * 1024
var copyBufPool = sync.Pool{
New: func() interface{} {
b := make([]byte, copyBufferSize)
return &b
},
}
// SkipReader skips a given number of bytes and then returns all
// remaining data.
type SkipReader struct {
@@ -285,21 +294,11 @@ func NewSkipReader(r io.Reader, n int64) io.Reader {
return &SkipReader{r, n}
}
const copyBufferSize = 32 * 1024
var copyBufPool = sync.Pool{
New: func() interface{} {
b := make([]byte, copyBufferSize)
return &b
},
}
// Copy is exactly like io.Copy but with reusable buffers.
func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
bufp := copyBufPool.Get().(*[]byte)
bufp := ODirectPoolLarge.Get().(*[]byte)
buf := *bufp
buf = buf[:copyBufferSize]
defer copyBufPool.Put(bufp)
defer ODirectPoolLarge.Put(bufp)
return io.CopyBuffer(dst, src, buf)
}