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

Do not flush underlying writer when buffer becomes full #173

Closed
owst opened this issue Oct 6, 2019 · 0 comments · Fixed by #174
Closed

Do not flush underlying writer when buffer becomes full #173

owst opened this issue Oct 6, 2019 · 0 comments · Fixed by #174

Comments

@owst
Copy link
Contributor

owst commented Oct 6, 2019

What version of the csv crate are you using?

master: fcdbea357739348b9eed2a0239e180213be78af9

Briefly describe the question, bug or feature request.

As mentioned in this issue of xsv, it seems that rust-csv is flushing the underlying writer when its internal buffer becomes full. This causes issues for xsv as the underlying writer is a TabWriter and calling flush causes side-effects other than writing out the buffer (specifically, it resets the internal state, "breaking" alignment of subsequently written data)

Include a complete program demonstrating a problem.

The reproduction with xsv is attached on the linked issue - using a small rust-csv buffer size leads to broken tabular layout.

What is the expected or desired behavior of the code above?

When the internal buffer becomes full, its contents should be written to the underlying writer, but the underlying writer should not be flushed. This seems to match with other buffering IO libraries, such as BufferedWriter in Java and rust's stdlib

owst added a commit to owst/rust-csv that referenced this issue Oct 6, 2019
BurntSushi pushed a commit that referenced this issue Jan 7, 2020
This fixes a bug where the CSV writer was erroneously flushing the
underlying writer when its internal buffer was full. Instead, when the
internal buffer is full, it should simply write the contents of the buffer
to the underlying writer. There is no need to flush it. Indeed, this causes
other problems such as those observed in
BurntSushi/xsv#151.

We are careful to ensure that calling `flush` explicitly still calls `flush`
on the underlying writer.

Fixes #173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant