Current doc says ReadFrom reads data from r until EOF or error. The return value n is the > number of bytes read. Any error except io.EOF encountered during the read > is also returned.
WriteTo writes data to w until there's no more data to write or when an > error occurs. The return value n is the number of bytes written. Any error > encountered during the write is also returned. Note that io.EOF is explicitly ignored in ReadFrom but it's a bit vague about how io.EOF should be handled in WriteTo. Should we return io.EOF or ignore it? An example type dataSource struct { // implementation details } func (src *dataSource) WriteTo(w io.Writer) (nn int64, err error) { buf := make([]byte, 32*1024) for { nr, er := src.internalRead(buf) // assume internalRead gets data from some internal source if nr > 0 { nw, ew := w.Write(buf[:nr]) nn += int64(nw) if ew != nil { err = ew break } } if er != nil { // What if er == io.EOF here? Shall we ignore it? err = er break } } } Since WriteTo can be used by io.Copy as a shortcut and io.Copy ignores io.EOF, I tend to think WriteTo should also ignore io.EOF. If so, the doc of io.WriteTo probably needs to be more explicit and consistent with io.ReadFrom. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.