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: document that Writer is buffered #30045

Closed
bmkessler opened this issue Jan 31, 2019 · 3 comments
Closed

encoding/csv: document that Writer is buffered #30045

bmkessler opened this issue Jan 31, 2019 · 3 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bmkessler
Copy link
Contributor

csv.Writer is implemented as a bufio.Writer, but this isn't clearly documented. The only place buffering is mentioned is in the Writer example and in the Flush() method. This makes it easy for a user to neglect to flush the underlying buffer and check for an error when writing a CSV, which can result in data loss. I believe the documentation on csv.Writer should clearly state that the implementation is buffered and thus must be flushed. Here is the current documentation:

// A Writer writes records to a CSV encoded file.
//
// As returned by NewWriter, a Writer writes records terminated by a
// newline and uses ',' as the field delimiter. The exported fields can be
// changed to customize the details before the first call to Write or WriteAll.
//
// Comma is the field delimiter.
//
// If UseCRLF is true, the Writer ends each output line with \r\n instead of \n.
type Writer struct {
	Comma   rune // Field delimiter (set to ',' by NewWriter)
	UseCRLF bool // True to use \r\n as the line terminator
	w       *bufio.Writer
}
@gopherbot
Copy link

Change https://golang.org/cl/160680 mentions this issue: encoding/csv: document that Writer is buffered

@CAFxX
Copy link
Contributor

CAFxX commented Feb 5, 2019

Why is the encoder buffered in the first place? It seems a completely unrelated concern...

@ianlancetaylor
Copy link
Contributor

Using a buffer is a simple way to pick up convenience methods like WriteString, WriteByte, WriteRune. Of course it then requires flushing.

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 1, 2019
@bcmills bcmills added this to the Go1.13 milestone Mar 1, 2019
@golang golang locked and limited conversation to collaborators Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants