1
0
mirror of https://github.com/golang/go synced 2024-11-17 15:34:42 -07:00

io: add ErrBadWriteCount

Change-Id: I9348ceae16dc38d42914959b5b0d7c5535db6a5a
This commit is contained in:
Tao Qingyun 2020-10-09 14:20:22 +08:00
parent d1da719b1d
commit 5bf70f4ee8

View File

@ -30,7 +30,7 @@ var ErrShortWrite = errors.New("short write")
// ErrShortBuffer means that a read required a longer buffer than was provided.
var ErrShortBuffer = errors.New("short buffer")
// ErrBadWriteCount means that a Write returned impossible count
// ErrBadWriteCount means that a write returned an impossible count.
var ErrBadWriteCount = errors.New("Write returned impossible count")
// EOF is the error returned by Read when no more input is available.
@ -412,15 +412,13 @@ func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) {
nr, er := src.Read(buf)
if nr > 0 {
nw, ew := dst.Write(buf[0:nr])
if nw > 0 {
written += int64(nw)
}
if ew != nil {
err = ew
if nw < 0 || nr < nw {
err = ErrBadWriteCount
break
}
if nw < 0 || nw > nr {
err = ErrBadWriteCount
written += int64(nw)
if ew != nil {
err = ew
break
}
if nr != nw {