3 ms·
That `Close` call only happens in the case that an error happened during either copying or closing. The point of checking errors on `Close` is so that you catch
by zeeboo 7y ago
That `Close` call only happens in the case that an error happened during either copying or closing. The point of checking errors on `Close` is so that you catch problems during flushing of any buffered writes. In this case, the `Close` is not to ensure the data is flushed, but to ensure that the file descriptor is released in error scenarios, justifying that the error need not be checked.
On the other hand,
w := try(s.Create(dst))
try(io.Copy(w, r))
try(w.Close())
return nil
this code has the problem where if there were an error in the `Copy`, the file descriptor would be leaked.
So, yes, one of the examples is wrong.