Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/csv: If the user provides a bufio.Reader then use it rather than creating a new one. #8954

Closed
gopherbot opened this issue Oct 17, 2014 · 5 comments

Comments

@gopherbot
Copy link

by brady:

In the csv.NewReader() call the input should be checked to see if it already is a
bufio.Reader and if so it should be used directly rather than creating a new buffered
reader. This would allow a reader to continue in the stream where a previous reader
might have failed.

In this example [ http://play.golang.org/p/j7B5yzdsdC ] It would be nice if we could get
the remaining file after the read call failed but it is completely consumed by the
reader.

This would require the following change on this line (or whatever more readable version
of this you prefer).
http://golang.org/src/pkg/encoding/csv/reader.go?s=3686:3721#L106

// NewReader returns a new Reader that reads from r.
func NewReader(r io.Reader) *Reader {
    if bufr, ok := r.(*bufio.Reader); ok {
        return &Reader{
            Comma: ',',
            r: bufr,
        }
    }
    return &Reader{
            Comma: ',',
            r:     bufio.NewReader(r),
    }
 }
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-none.

@ianlancetaylor
Copy link
Contributor

Comment 2:

After the 1.4 release consider sending in the change as described at
http://golang.org/doc/contribute.html .  Thanks.

@gopherbot
Copy link
Author

Comment 3 by 2852914@wessie.info:

I was under the impression bufio.NewReader already does this internally, the code seems
to agree http://golang.org/src/pkg/bufio/bufio.go?s=1234:1284#L36

@gopherbot
Copy link
Author

Comment 4 by brady:

Hey cool! I didn't know that! Seems like all is well then and this bug can be closed. =)

@ianlancetaylor
Copy link
Contributor

Comment 5:

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants