Skip to content

[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

Closed
wants to merge 2 commits into from
Closed

[compression] NewZstdCompressor #9504

wants to merge 2 commits into from

Conversation

dan-stowell
Copy link
Contributor

This change introduce NewZstdCompressor(...) (copied and adapted from pebble_cache.NewZstdCompressor(...).

A follow-on change will wrap a cachetools.UploadWriter with this compressor when zstd compression is requested.

@@ -116,6 +116,35 @@ func (d *zstdDecompressor) Close() error {
return lastErr
}

func NewZstdCompressor(w io.Writer, compressBuf []byte) io.Writer {
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@dan-stowell dan-stowell marked this pull request as draft May 30, 2025 18:05
compressBuf []byte
}

func (z *zstdCompressor) Write(decompressedBytes []byte) (int, error) {
Copy link
Contributor

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 {
Copy link
Contributor

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.

@dan-stowell
Copy link
Contributor Author

Closing in favor of #9521

@dan-stowell dan-stowell deleted the dan-zstd-comp branch June 2, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants