diff --git a/go/mcap/writer.go b/go/mcap/writer.go index 7638abe6e..7305ca61b 100644 --- a/go/mcap/writer.go +++ b/go/mcap/writer.go @@ -752,13 +752,16 @@ const ( ) type CustomCompressor interface { - Compressor() ResettableWriteCloser + NewCompressor() ResettableWriteCloser Compression() CompressionFormat } // NewCustomCompressor returns a structure that may be supplied to writer // options as a custom chunk compressor. -func NewCustomCompressor(compression CompressionFormat, compressor ResettableWriteCloser) CustomCompressor { +func NewCustomCompressor( + compression CompressionFormat, + compressor func() (ResettableWriteCloser, error), +) CustomCompressor { return &customCompressor{ compression: compression, compressor: compressor, @@ -767,7 +770,7 @@ func NewCustomCompressor(compression CompressionFormat, compressor ResettableWri type customCompressor struct { compression CompressionFormat - compressor ResettableWriteCloser + compressor func() (ResettableWriteCloser, error) } func (c *customCompressor) Compressor() ResettableWriteCloser { diff --git a/go/mcap/writer_test.go b/go/mcap/writer_test.go index f56227115..c121bbed8 100644 --- a/go/mcap/writer_test.go +++ b/go/mcap/writer_test.go @@ -703,16 +703,18 @@ func assertReadable(t *testing.T, rs io.ReadSeeker) { func TestBYOCompressor(t *testing.T) { buf := &bytes.Buffer{} // example - custom lz4 settings - lzw := lz4.NewWriter(nil) blockCount := 0 - require.NoError(t, lzw.Apply(lz4.OnBlockDoneOption(func(int) { - blockCount++ - }))) writer, err := NewWriter(buf, &WriterOptions{ - Chunked: true, - ChunkSize: 1024, - Compressor: NewCustomCompressor("lz4", lzw), + Chunked: true, + ChunkSize: 1024, + Compressor: NewCustomCompressor("lz4", func() (ResettableWriteCloser, error) { + lzw := lz4.NewWriter(nil) + require.NoError(t, lzw.Apply(lz4.OnBlockDoneOption(func(int) { + blockCount++ + }))) + return lzw, nil + }), }) require.NoError(t, err)