22 lines
433 B
Go
22 lines
433 B
Go
package grand
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
// MustRead tries to fill p with len(p) bytes from r. If it haven't read enough bytes, then an
|
|
// error returns. So if nil error returns, then p must have read len(p) bytes. Otherwise, only
|
|
// p[:n] are read from r.
|
|
func MustRead(r io.Reader, p []byte) (int, error) {
|
|
n := 0
|
|
for len(p) > 0 {
|
|
m, err := r.Read(p)
|
|
if err != nil {
|
|
return n + m, err
|
|
}
|
|
p = p[m:]
|
|
n += m
|
|
}
|
|
return n, nil
|
|
}
|