From fdf371c29fb992b37f696ca3b382a4cdd0833608 Mon Sep 17 00:00:00 2001 From: Lakshay Kalbhor Date: Mon, 4 Dec 2023 06:23:36 +0530 Subject: [PATCH] use bytes buffer instead of ReadAll --- pkg/kgo/compression.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/kgo/compression.go b/pkg/kgo/compression.go index 208951a6..27bfe6db 100644 --- a/pkg/kgo/compression.go +++ b/pkg/kgo/compression.go @@ -5,7 +5,7 @@ import ( "compress/gzip" "encoding/binary" "errors" - "io/ioutil" + "io" "runtime" "sync" @@ -268,7 +268,11 @@ func (d *decompressor) decompress(src []byte, codec byte) ([]byte, error) { if err := ungz.Reset(bytes.NewReader(src)); err != nil { return nil, err } - return ioutil.ReadAll(ungz) + out := new(bytes.Buffer) + if _, err := io.Copy(out, ungz); err != nil { + return nil, err + } + return out.Bytes(), nil case 2: if len(src) > 16 && bytes.HasPrefix(src, xerialPfx) { return xerialDecode(src) @@ -278,7 +282,11 @@ func (d *decompressor) decompress(src []byte, codec byte) ([]byte, error) { unlz4 := d.unlz4Pool.Get().(*lz4.Reader) defer d.unlz4Pool.Put(unlz4) unlz4.Reset(bytes.NewReader(src)) - return ioutil.ReadAll(unlz4) + out := new(bytes.Buffer) + if _, err := io.Copy(out, unlz4); err != nil { + return nil, err + } + return out.Bytes(), nil case 4: unzstd := d.unzstdPool.Get().(*zstdDecoder) defer d.unzstdPool.Put(unzstd)