http://codereview.appspot.com/6548047/diff/3/src/pkg/bufio/bufio.go#newcode378
src/pkg/bufio/bufio.go:378: // WriteTo first writes the contents of the
buffer into the writer,
On 2012/09/24 15:34:09, rsc wrote:
> This describes how good the implementation is. The reader should
assume it is
> good. The coment should say what the function's effect is.
> // WriteTo copies data from the reader into the writer w until there's
no more
> // data to write or an error occurs. It returns the number of bytes
written
> // and the encountered error, if any.
> (mostly lifted from io.WriterTo's docs)
Didn't notice Tip io.WriterTo had docs, will go with brad's suggestion.
On 2012/09/24 15:34:09, rsc wrote:
> Writers are almost always called w, not wtr.
Noted
On 2012/09/24 15:34:09, rsc wrote:
> The sequencing here is a little tricky. You want to delay processing
the read
> error until after you write what did get read, as a write error then
would
> correspond to an earlier input byte than the read error. I think this
would
> work:
> for b.fill(); b.r < b.w; b.fill() {
> m, err := b.writeTo(w)
> n += m
> if err != nil {
> return n, err
> }
> }
> if b.err == io.EOF {
> b.err = nil
> }
> return n, b.readErr()
Fixed and added tests for the various permutations of errors.
On 2012/09/24 15:34:09, rsc wrote:
> writeTo is fine. the 'Buf' is unnecessary.
> Also just call the writer w.
I'll rename it, but I don't think its the right decision. I feel like
the WriteTo code is less clear now that there is a private writeTo
method that only deals with the buffer. writeBufTo tells the reader that
it only is dealing with what is buffered.
On 2012/09/24 15:34:09, rsc wrote:
> Interesting constant. Did you mean 8<<10 (8192)?
Ugh, thats embarrassing. Fixed.
On 2012/09/24 15:34:09, rsc wrote:
> You never use this variable again. Eliminate it:
> r := NewReader(bytes.NewReader(input))
Done
http://codereview.appspot.com/6548047/diff/3/src/pkg/bufio/bufio_test.go#newcode775
src/pkg/bufio/bufio_test.go:775:
On 2012/09/24 15:34:09, rsc wrote:
> Can collapse the next 8 lines into
> if n != int64(len(input)) || err != nil {
> t.Fatalf("r.WriteTo(w) = %d, %v, want %d, nil", n, err,
len(input))
> }
Moved n,err := into the initializer block of the if as well
On 2012/09/24 15:34:09, rsc wrote:
> Echo the values back in the same order as the comparison, and use Go
syntax when
> possible, like in the new Fatalf in the last comment.
> t.Errorf("after write: out[%#x] = %#x, want %#x", i, val, input[i])
Done
On 2012/09/24 15:34:09, rsc wrote:
> Please call this 'onlyReader'. The type name should appear verbatim,
without
> additional spaces or case changes:
> // An onlyReader only implements io.Reader, no matter what other
methods
> // the underlying implementation may have.
Done and ditto for the writer.
http://codereview.appspot.com/6548047/