-
Notifications
You must be signed in to change notification settings - Fork 96
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
Conversation
ef5399b
to
af98e5a
Compare
go/mcap/Makefile
Outdated
@@ -1,5 +1,5 @@ | |||
test: | |||
go test ./... | |||
go test -cover ./... |
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.
remove from this PR?
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.
done
98710a6
to
cb07c24
Compare
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.
cb07c24
to
f0597db
Compare
d0e63c1
to
9d68a25
Compare
Reset(io.Writer) | ||
} | ||
|
||
// ResettableReadCloser implements io.ReadCloser and adds a Reset method. |
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.
io.Reader
// ResettableWriteCloser implements io.WriteCloser and adds a Reset method. | ||
type ResettableWriteCloser interface { | ||
io.WriteCloser | ||
Reset(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.
perhaps Reset should return error? lz4's does not, but zstd's does.
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.
Just a small question / food for thought, but this seems good to me.
go/mcap/writer.go
Outdated
case CompressionZSTD: | ||
switch { | ||
case opts.Compressor != nil: // must be top | ||
if opts.Compression == "" { |
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.
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?
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.
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.
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.
if we used a functional options patter for this it would be better - we could tell the user to pass WithCompressor(compression string, compressor ...)
.
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.
but we can't make that change here unfortunately
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 haven't looked closely at the implementation but I approve of this configuration approach.
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.
Don't forget to bump the library version unless you plan to handle this in a follow up PR.
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.