Skip to content

Commit

Permalink
use bytes buffer instead of ReadAll
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshay Kalbhor committed Dec 5, 2023
1 parent a6d10d4 commit fdf371c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/kgo/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"encoding/binary"
"errors"
"io/ioutil"
"io"
"runtime"
"sync"

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit fdf371c

Please sign in to comment.