Files
imgproxy/ioutil/ioutil.go
2025-08-19 18:46:56 +06:00

20 lines
541 B
Go

package ioutil
import "io"
// TryReadFull acts like io.ReadFull with a couple of differences:
// 1. It doesn't return io.ErrUnexpectedEOF if the reader returns less data than requested.
// Instead, it returns the number of bytes read and the error from the last read operation.
// 2. It always returns the number of bytes read regardless of the error.
func TryReadFull(r io.Reader, b []byte) (n int, err error) {
var nn int
toRead := len(b)
for n < toRead && err == nil {
nn, err = r.Read(b[n:])
n += nn
}
return n, err
}