Skip to content
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

Go: add support for custom compression #968

Merged
merged 5 commits into from
Sep 12, 2023
Merged

Conversation

wkalt
Copy link
Contributor

@wkalt wkalt commented Sep 8, 2023

Adds support for bringing custom compressors and decompressors to the go lexer and writer.

For the writer, a ResettableWriteCloser is accepted. For the reader, a map of compression format to ResettableReader is accepted. If the reader implements io.Closer we'll call that on file close.

@wkalt wkalt requested a review from james-rms September 8, 2023 02:28
@wkalt wkalt force-pushed the ticket/fg-4938/byo-compression branch from ef5399b to af98e5a Compare September 8, 2023 02:28
go/mcap/Makefile Outdated
@@ -1,5 +1,5 @@
test:
go test ./...
go test -cover ./...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Wyatt Alt added 2 commits September 7, 2023 22:23
Adds support for bringing custom compressors and decompressors to the go
lexer and writer.

For the writer, a ResettableWriteCloser is accepted. For the reader, a
map of compression format to ResettableReader is accepted. If the reader
implements io.Closer we'll call that on file close.
Reset(io.Writer)
}

// ResettableReadCloser implements io.ReadCloser and adds a Reset method.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.Reader

// ResettableWriteCloser implements io.WriteCloser and adds a Reset method.
type ResettableWriteCloser interface {
io.WriteCloser
Reset(io.Writer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps Reset should return error? lz4's does not, but zstd's does.

Copy link
Contributor

@bryfox bryfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small question / food for thought, but this seems good to me.

case CompressionZSTD:
switch {
case opts.Compressor != nil: // must be top
if opts.Compression == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first reaction is that the interface feels a little strange with 'compressor' and 'compression' decoupled. I don't see where Compression is used in the case of a custom compressor, but presumably an lz4 writer should always be accompanied by type LZ4. Is Compression required if a compressor is passed? If so, would it make sense to have Compressor contain the compression, and embed the ResettableWriteCloser type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an option, but what I don't really like about it is it forces all consumers of this to implement their own Compressor type (to expose a Compression() string method), whereas the current interface has a chance of matching the compressors out of the box - although I think this will only be true of one of lz4 and zstd, depending on whether or not Reset() is chosen to send an error out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we used a functional options patter for this it would be better - we could tell the user to pass WithCompressor(compression string, compressor ...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we can't make that change here unfortunately

Copy link
Collaborator

@james-rms james-rms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked closely at the implementation but I approve of this configuration approach.

Copy link
Collaborator

@james-rms james-rms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to bump the library version unless you plan to handle this in a follow up PR.

@wkalt wkalt merged commit d9cabbe into main Sep 12, 2023
24 checks passed
@wkalt wkalt deleted the ticket/fg-4938/byo-compression branch September 12, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants