--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/28eb98d4-c531-413d-b7f1-790b2600309fn%40googlegroups.com.
Thanks for the response. Couple of points:
> 1. You don't get notified about checksum mismatches or the like. i.e. the
> data you read might be corrupted and you might not realize it.
I dont think this is true. I tried with this file [1], and Close returns the
same error as, for example io.Copy, so again Close seems redundant.
> Either way, it's also just good hygiene to *always* call `Close` on an
> `io.Closer`. If a library gives you a `Close` method, it usually expects you
> to call it and there's really no point in not doing it.
Even with something like net/http#Head? Seems pointless in that case too.
// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/858087d9b1fe39c8e2949559b8677e21b1f8fbb1.camel%40kortschak.io.
Thanks for the responses, but I am not convinced. Other than "its just good
practice", I havent seen a single concrete example where not closing a gzip
reader would cause a problem.
Until that happens, I am just going to stop doing it in my code.
No other compress reader even has a Close method, so I think Im fine:
- https://golang.org/pkg/compress/bzip2
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAP8dQmsfC6WW-UB6EZmGbFcpkAFODVr0uUMkGAkcuwZuYUuMJQ%40mail.gmail.com.
Internally close calls z.decompressor.Close() where decompressor is typically obtained via flat.NewReader(r) which states
NewReader returns a new ReadCloser that can be used to read the uncompressed version of r. If r does not also implement io.ByteReader, the decompressor may read more data than necessary from r. It is the caller's responsibility to call Close on the ReadCloser when finished reading.
The ReadCloser returned by NewReader also implements Resetter.
It's been some time now but I'm pretty sure I've seen gzip Reader fail silently when the Close error wasn't correctly checked, so there is a good reason why you should not only call Close but also confirm it returns nil.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAP8dQmsmqFqOu-iS9-e%3D3FZimG4nybdwM-d53JccaCuGoXJjRg%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAP8dQmvoR7COEsEB0PvuSCFC8cvF-9NuxTGBv7SZ06-phtekWw%40mail.gmail.com.
OK, so all all these decades of experience, why cant anyone produce a small
program to demonstrate the problem?
You calling "go look through 3200 lines of Go code" (not including tests) [1] a
"clear path" is a dubious comment at best.
Either they cant be bothered, or they dont
actually know how to create a program that would demonstrate a bad situation
that could arise from not closing gzip reader.
I am not questioning anyones knowledge, I am just asking for a demonstration,
rather than "do it because we said so".
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAP8dQmvoR7COEsEB0PvuSCFC8cvF-9NuxTGBv7SZ06-phtekWw%40mail.gmail.com.
So I think it can be safe to omit
using gzip Reader Close in the general case.
More practically though, most programmers would probably prefer to follow guidance provided by the authors of the library they are using because by virtue of having written the library, the authors probably understand not only the library's implementation and technical constraints better than the user but also tend to have a better grasp of the problem domain.