-
-
Notifications
You must be signed in to change notification settings - Fork 43
Add a new method Flush
to reuse writer
#18
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
Conversation
3fb956e
to
224570b
Compare
padding/padding.go
Outdated
if w.lineLen == 0 { | ||
return nil | ||
// Close will finish the padding operation and then closes the writer. | ||
// Notice that the writer will never be wrote again after it closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo/grammar: "Notice that the writer can never be written to again once it has been closed."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the correction!
padding/padding_test.go
Outdated
t.Error(err) | ||
} | ||
|
||
f.closed = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you manually set this? Shouldn't closed
already be true after f.Close()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, closed
won't be set to true if error occurs.
I must admit this added a bit more overhead than initially anticipated. All reasonable changes, but I wonder if it's really worth adding it, as it certainly hinders readability & understandability a bit. Maybe we could/should abstract the generic Writer caching away, especially if we want to introduce the same API pattern to the other packages in reflow. |
Thanks for the feedback! In my opinion, all writers in reflow is kind of like Perhaps the most commonly used methods are String and Bytes. The writers they use internally can be reused. |
Btw if we can combine But it is bigger changes haha. It's just an idea and up to you 😄 . |
Good point, indeed. Maybe we should follow that API. On the other side I always liked this being compatible with an |
Maybe we should make these structures non-closable (internally), and instead have |
That may be something like ioutil.NopCloser, right? Oh as of go 1.16 will be io.NopCloser. |
Updated. Please take a look @muesli |
e02df04
to
c5d584b
Compare
Not quite, as the |
Got it. And other packages in reflow should have the same API pattern. |
Yeah I think we should keep them consistent. |
I will fix them all after |
I think this PR is looking good now! Thanks for all the iterations you went through. And once again: thank you for all your PRs! |
This PR add a new method
Flush
to reuse writer. Here is the code snippetFurther more, when writer closed, it shouldn't be used again according to #13(comment).
Btw I'm not sure the descriptions about
Flush
andClose
conform to your standard. So if you any ideas, please let me know.