mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-23 09:35:50 +02:00
20 lines
541 B
Go
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
|
|
}
|