Skip to content

Commit

Permalink
CompressingReader: support older Go versions
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Dubov <[email protected]>
  • Loading branch information
oakad committed Dec 8, 2023
1 parent 4a80a2f commit 7613989
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions compressing_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,10 @@ func (wr *ovWriter) reset(out []byte) bool {
wr.ov = wr.ov[ : 0]
wr.ovPos = 0
wr.dataPos = ovRem
}

if wr.ovPos > 0 {
} else if wr.ovPos > 0 {
wr.ov = wr.ov[ : 0]
wr.ovPos = 0
wr.dataPos = 0
}

wr.data = out
Expand Down
11 changes: 5 additions & 6 deletions compressing_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package lz4_test
import (
"bytes"
"fmt"
"io"
"os"
"io/ioutil"
"strings"
"testing"

Expand Down Expand Up @@ -35,26 +34,26 @@ func TestCompressingReader(t *testing.T) {
option := option
t.Parallel()

raw, err := os.ReadFile(fname)
raw, err := ioutil.ReadFile(fname)
if err != nil {
t.Fatal(err)
}
r := io.NopCloser(bytes.NewReader(raw))
r := ioutil.NopCloser(bytes.NewReader(raw))

// Compress.
zcomp := lz4.NewCompressingReader(r)
if err := zcomp.Apply(option, lz4.CompressionLevelOption(lz4.Level1)); err != nil {
t.Fatal(err)
}

zout, err := io.ReadAll(zcomp)
zout, err := ioutil.ReadAll(zcomp)
if err != nil {
t.Fatal(err)
}

// Uncompress.
zr := lz4.NewReader(bytes.NewReader(zout))
out, err := io.ReadAll(zr)
out, err := ioutil.ReadAll(zr)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 7613989

Please sign in to comment.