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

No way to flush a Writer #18

Open
cuboci opened this issue Nov 12, 2014 · 1 comment
Open

No way to flush a Writer #18

cuboci opened this issue Nov 12, 2014 · 1 comment

Comments

@cuboci
Copy link

cuboci commented Nov 12, 2014

Hi,

while writing some XML (generated by xml.Marshal) to an iconv.Writer I noticed some data getting cut off upon my program exiting. If I used the underlying io.Writer directly (that is, without converting the data), that didn't happen. Unfortunately, there is no way to flush iconv.Writer's internal buffer explicitely. Am I missing something or is this a bug?

Cheers,
Chris

@djimenez
Copy link
Owner

You're not missing anything, the code is - there should be a Flush and / or Close for cases like this where the last Write didn't push all of the buffered bytes to the next Writer in the chain. bufio.Writer has some other methods to understand the buffer (like Available and Buffered) which could be useful to add as well.

If you look at how xml.Marshal works, it uses a bufio.Writer on top of the writer you give it and then calls Flush on it before returning - however bufio.Writer's Flush implementation doesn't try to do that down the chain. Which is unfortunate.

I think a possible workaround in the meantime (though I haven't tried it) is to trying sending an empty buffer to the Write method - it might still trigger the attempt to empty the buffer.

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

No branches or pull requests

2 participants