golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
120.1k stars 17.24k forks source link

proposal: encoding/csv add a new constructor with a configurable buffer size #67128

Closed thecoldwine closed 2 weeks ago

thecoldwine commented 2 weeks ago

Proposal Details

Currently encoding/csv Writer is currently exposing only one constructor using bufio.NewWriter constructor. This hardcodes the buffer size to 4096 which sometimes is not enough and code panics if a single csv record is longer than this length (assuming we're flushing after every record).

Proposal:

Add one more constructor that allows to control the buffer size, so single row can fit into the buffer:

func NewWriterWithBufferSize(w io.Writer, size int) *[Writer]
ianlancetaylor commented 2 weeks ago

Note that you can get the same effect using

csv.NewWriter(bufio.NewWriterSize(w, size))

See https://pkg.go.dev/bufio#NewWriterSize .

thecoldwine commented 2 weeks ago

Closing as irrelevant then, since the provided standard solution works well, thanks for the prompt feedback.