1
0
mirror of https://github.com/golang/go synced 2024-11-18 00:54:45 -07:00

io: make CopyBuffer docs state when buf is not used

Document that if either src implements the WriteTo interface
or if dst implements the ReaderFrom interface, then
buf will not be used.

Fixes #32276

Change-Id: Id0a69c90e255e694e7ec9f79ffe4d8391441e59e
GitHub-Last-Rev: 750e7e86d5
GitHub-Pull-Request: golang/go#32279
Reviewed-on: https://go-review.googlesource.com/c/go/+/179137
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
sandyskies 2019-10-21 17:32:13 +00:00 committed by Emmanuel Odeke
parent 58b031949b
commit 03978a97e5

View File

@ -368,6 +368,9 @@ func Copy(dst Writer, src Reader) (written int64, err error) {
// provided buffer (if one is required) rather than allocating a // provided buffer (if one is required) rather than allocating a
// temporary one. If buf is nil, one is allocated; otherwise if it has // temporary one. If buf is nil, one is allocated; otherwise if it has
// zero length, CopyBuffer panics. // zero length, CopyBuffer panics.
//
// If either src implements WriterTo or dst implements ReaderFrom,
// buf will not be used to perform the copy.
func CopyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) { func CopyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) {
if buf != nil && len(buf) == 0 { if buf != nil && len(buf) == 0 {
panic("empty buffer in io.CopyBuffer") panic("empty buffer in io.CopyBuffer")