-
Notifications
You must be signed in to change notification settings - Fork 18.1k
compress/gzip: allow multi-stream io.Reader reuse #30234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR (HEAD: 6cc6410) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/162737 to see it. Tip: You can toggle comments from me using the |
Message from Brad Fitzpatrick: Patch Set 1: This would need a test. Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
Message from Jeremy Jay: Patch Set 1:
I can do that. Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
This PR (HEAD: 241093b) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/162737 to see it. Tip: You can toggle comments from me using the |
Message from Brad Fitzpatrick: Patch Set 2:
I don't know the existing tests from memory at least. Ideally no testdata if possible (doesn't seem required?), and don't modify any existing tests. Just add new tests, copy/pasting if needed. Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
Message from Jeremy Jay: Patch Set 2:
That's what I did with patch set 2. Should be ready to go! Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
Message from Joe Tsai: Patch Set 2: In isolation, I understand this change, but it makes Reader.Reset and Writer.Reset asymmetrical, since Writer.Reset still doesn't permit taking in nil. Also, using nil to signal reusing the underlying reader is a somewhat odd API. As you mentioned in the issue, there is a workaround for this. The documentation for Reader.Multistream currently states:
Thus, it explicitly calls out the fact that users of this feature need to provide an io.ByteReader to properly use this feature. Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
Message from Jeremy Jay: Patch Set 2:
I agree it's odd. Certainly easy to mimic on Writer I'd the asymmetry is problematic, though I don't see any point to that either. Open to other options...
While this is true, it also doesn't explicitly mention that the underlying io.Reader is wrapped and this behavior is expected. It does not state that passing the original io.Reader to Reset will not work UNLESS it implements ByteReader. Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
Message from Joe Tsai: Patch Set 2: I thought about this some more and I'm more hesitant to use Reset(nil) to signal that the underlying reader should be re-used. Seeing that used in code does not make it clear what's happening without reading the documentation. In fact, it's the opposite of what the call seems to be doing. Furthermore, this would make gzip different from the other compress packages where Reset(nil) explicitly clears the underlying reader and is sometimes done to help the Go GC be able to reclaim the memory for the underlying reader. This is useful if a compression Reader is cached within a larger data structure.
Actually, it does. The documentation for gzip.NewReader says:
This implies some form of wrapping or internal buffering.
Alternatives:
Overall, I'm inclined to make no changes. In my opinion, dealing with individual GZIP files in a multistream file is fundamentally clunky and there is a workaround as you noted in the issue. Please don’t reply on this GitHub thread. Visit golang.org/cl/162737. |
Fixes #30230