Also as far as I’m aware (I could be wrong about this), deferring to close the
w.Close() should be fine since it’s not flushing to disk the same way that closing a regular file needs to, since closing the regular file is what will be flushed.
Edit: Actually scratch that, it should be getting error checked anyway… Literally everything that has an error should be checked in proper code.
I’ve updated those parts of the zip and tar examples.
I’m not actually sure if it’s necessary to check the deferred error in the
zip.OpenReader example, only because in the actual test in the Go stdlib, they open it and just
defer rc.Close(). You can find examples of that here: https://golang.org/src/archive/zip/reader_test.go, but it can’t hurt so may as well just do it.
I will one day get around to making sure that all files that are opened are closed correctly, just because like I said I really wrote most of these as I learnt the basics of Go, but a lot of examples online don’t mention these important things like Jakob and Dave mentioned here, so it’s hard to know what’s right when you start.
I’m sure there are plenty of things I still do wrong from when I first started learning
Just btw, if there is literally anything else you are unsure about, or you want better/more complex examples for literally anything in that repo, just let me know, even if it’s just to fix things like this, just because I’m usually doing other things so I don’t spend much time thinking about that repo these days, but posted it so it could help other people.
So basically all I’m saying is that I am more than happy to change things on request, but it may be a while before I properly go through myself randomly and add more/better/complex examples and fix the error checking for things like above properly
Thanks, by looking at the changes things make more sense to me now
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.