-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Serial File Opening #553
Serial File Opening #553
Conversation
return f.Reader.Read(p) | ||
} | ||
|
||
func (f *ReaderFile) Close() error { |
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.
It's better to accept a ReadCloser and allow clients to wrap their non-closing Readers in a Closer wrapper (one which has no effect).
Secretly introspecting and closing a client's Reader is harder to explain to callers and can result in surprising behavior.
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.
yeah i got bitten by this :/ -- i've since stopped doing it. it's also fine to leave closing to the user in many cases.
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.
just for the record the NopCloser is here:
package ioutil
func NopCloser(r io.Reader) io.ReadCloser
… cast reader to Closer
Strange, I am just starting to play around with ipfs, and apparently got exactly this error:
This was with |
This resolves #536.
It creates a new kind of
commands.File
called SerialFile, which only needs to open oneos.File
at a time. It's hella clean since it handles all of the file opening/closing on its own.