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
proposal: io: accept ErrShortWrite if Write reports no error #49474
Comments
Change https://golang.org/cl/362514 mentions this issue: |
cc @griesemer @ianlancetaylor @bradfitz CL 362514 is also sent for the proposed change. |
I think the current feedback from io.Copy is very useful to re-adjust your copy buffers. That is also a sane way to detect whether you missed write buffering. If your read and write chunk sizes are not aligned you need to wrap it in a bufio.Writer and bufio.Reader I think. Until now I thought that is exactly their purpose. If the current bufio package doesn't help your use case I would like to hear more about it. |
The |
Interesting, sorry that didn't read through the requirement of io.Writer. If so then this proposal also implies relaxing the requirement of
Why is it backward-incompatible? The requirement is only relaxed, isn't it? |
Because relaxing the requirement breaks approximately every piece of code which calls |
I assume this must be a misunderstanding. If all existing Write guarantees a complete write, then relax the requirement does not impact any existing code because |
Yes, exactly: You need to change If the |
Any writer that wants that behavior is required to do its own buffering. That is part of the contract of |
Currently, when a writer Writes non-zero bytes content and also does not report an error,
the
io.Copy
will reportio.ErrShortWrite
. For example, this test will fail:https://play.golang.org/p/ixBBi5pm6mh
If an incomplete writer writes incomplete content but postpones the task to the next write, it would be better to call Write again until all read has been written, so that the above test can pass.
The text was updated successfully, but these errors were encountered: