Skip to content

Commit

Permalink
Fix CompressMaxSize() for ZLib provider (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Jul 7, 2020
1 parent ee17df9 commit 6a80299
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pulsar/internal/compression/zlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func NewZLibProvider() Provider {
}

func (zlibProvider) CompressMaxSize(originalSize int) int {
return int(float32(originalSize) * 1.10)
// Use formula from ZLib: https://github.com/madler/zlib/blob/cacf7f1d4e3d44d871b605da3b647f07d718623f/deflate.c#L659
return originalSize +
((originalSize + 7) >> 3) + ((originalSize + 63) >> 6) + 11
}

func (zlibProvider) Compress(dst, src []byte) []byte {
Expand Down

0 comments on commit 6a80299

Please sign in to comment.