-
Notifications
You must be signed in to change notification settings - Fork 106
[compression] NewZstdCompressor #9504
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
@@ -116,6 +116,35 @@ func (d *zstdDecompressor) Close() error { | |||
return lastErr | |||
} | |||
|
|||
func NewZstdCompressor(w io.Writer, compressBuf []byte) io.Writer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary for the caller to pass the buffer slice? Can they pass a length instead?
If the answer is that it's needed then please add a doc string for the function and document how compressBuf
should be used/sized by the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary (though other public functions accept a compressBuf
).
Safe to create a variabled-sized buffer pool for the package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're better off leaving the buffer allocation to the caller, as you're doing now. That way the user can decide if they want to use a pool, or allocate a new buffer, or reuse a buffer they already have.
But do leave a comment on the exported function.
compressBuf []byte | ||
} | ||
|
||
func (z *zstdCompressor) Write(decompressedBytes []byte) (int, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: uncompressedBytes is slightly nicer than decompressedBytes. The latter implies that they were originally compressed.
@@ -116,6 +116,35 @@ func (d *zstdDecompressor) Close() error { | |||
return lastErr | |||
} | |||
|
|||
func NewZstdCompressor(w io.Writer, compressBuf []byte) io.Writer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're better off leaving the buffer allocation to the caller, as you're doing now. That way the user can decide if they want to use a pool, or allocate a new buffer, or reuse a buffer they already have.
But do leave a comment on the exported function.
Closing in favor of #9521 |
This change introduce
NewZstdCompressor(...)
(copied and adapted frompebble_cache.NewZstdCompressor(...)
.A follow-on change will wrap a
cachetools.UploadWriter
with this compressor when zstd compression is requested.