GZIP: close underlying Writer #1089
Closed
flrdv
started this conversation in
Ideas/Features
Replies: 1 comment 3 replies
-
No. First of all, it is bad practice to close a provided stream. Even if you are done with the stream you have no idea what the caller intends. They may want to write more. Second of all it would be breaking existing code. Third, it would be incompatible with the standard library. And I don't think you would have much luck arguing this change to the Go team for the 2 reasons above. You will have to deal with this, since you, as the caller, are responsible for closing the writers. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
GZIP writer doesn't close the underlying
io.Writer
whenClose()
is called. Unsure about flate and zstd.This is a problem when writers are chained together.
I'm passing my chunked transfer-encoding writer to
gzip.Writer#Reset()
method, which relies on theClose()
call to write the last zero-length chunk and flush the buffer.There are a few workarounds, e.g. storing all chained writers in a slice nearby or wrapping each one, thereby building a tree/linked-list, enabling a way to manually close each one. However, I personally find them pretty ugly and would prefer the
gzip.Writer#Close()
to do the job.I can open a PR if you agree on this.
Beta Was this translation helpful? Give feedback.
All reactions