You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your program is buggy. You're capturing the buffer before you call Writer.Close, but the Close does the final flush and writes the final bit of the gzip. Also, don't ignore the return value of Close whenever writing is involved.
What version of Go are you using (
go version
)?go 1.8.1
What operating system and processor architecture are you using (
go env
)?linux amd64
What did you do?
I put .Close() for a gzip writer in a defer statement (writing to a file).
The simplest example I found that replicates this behavior is here: https://play.golang.org/p/WmZtqtvnyN
And if I swap the defer for a non-deferred close: https://play.golang.org/p/KAdLfmUlHQ
NOTE: I originally did this with a file. This is not just for bytes.Buffer
What did you expect to see?
The data is successfully saved.
What did you see instead?
Gzip output is corrupted.
The text was updated successfully, but these errors were encountered: