Increase cgolz4 Writer buf len for older lz4 libs
diff --git a/lib/cgolz4/cgolz4.go b/lib/cgolz4/cgolz4.go
index dc9563d..84c226c 100644
--- a/lib/cgolz4/cgolz4.go
+++ b/lib/cgolz4/cgolz4.go
@@ -346,6 +346,12 @@
return nil
}
+func minDstLenForBlockMaxLen() uint64 {
+ return uint64(C.cgolz4_compress_min_dst_len(C.uint32_t(blockMaxLen)))
+}
+
+const writerBufLen = 2*blockMaxLen + 16
+
// Writer compresses to the lz4 format.
//
// Compressed bytes may be buffered and not sent to the underlying io.Writer
@@ -353,7 +359,7 @@
//
// The zero value is not usable until Reset is called.
type Writer struct {
- buf [2 * blockMaxLen]byte
+ buf [writerBufLen]byte
j uint32
w io.Writer
begun bool
diff --git a/lib/cgolz4/cgolz4_test.go b/lib/cgolz4/cgolz4_test.go
index 4748ced..3f9b79e 100644
--- a/lib/cgolz4/cgolz4_test.go
+++ b/lib/cgolz4/cgolz4_test.go
@@ -89,3 +89,9 @@
}
}
}
+
+func TestWriterBufIsLargeEnough(tt *testing.T) {
+ if m := minDstLenForBlockMaxLen(); writerBufLen < m {
+ tt.Fatalf("writerBufLen: got %d, want >= %d", writerBufLen, m)
+ }
+}