From 9291662f3bb37a34ae2505af60789771b3bf6d65 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Sun, 18 Jun 2023 02:06:11 +0900 Subject: [PATCH 1/4] feat: add io.ByteReader optimization --- internal/lzma/reader.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/internal/lzma/reader.go b/internal/lzma/reader.go index 2086846..9f47a2a 100644 --- a/internal/lzma/reader.go +++ b/internal/lzma/reader.go @@ -40,8 +40,7 @@ func NewReader(p []byte, s uint64, readers []io.ReadCloser) (io.ReadCloser, erro h := bytes.NewBuffer(p) _ = binary.Write(h, binary.LittleEndian, s) - - lr, err := lzma.NewReader(io.MultiReader(h, readers[0])) + lr, err := lzma.NewReader(multiReader(h, readers[0])) if err != nil { return nil, err } @@ -51,3 +50,32 @@ func NewReader(p []byte, s uint64, readers []io.ReadCloser) (io.ReadCloser, erro r: lr, }, nil } + +func multiReader(b *bytes.Buffer, rc io.ReadCloser) io.Reader { + mr := io.MultiReader(b, rc) + if br, ok := rc.(io.ByteReader); ok { + return &multiByteReader{ + b: b, + br: br, + mr: mr, + } + } + return mr +} + +type multiByteReader struct { + b *bytes.Buffer + br io.ByteReader + mr io.Reader +} + +func (m *multiByteReader) ReadByte() (byte, error) { + if m.b.Len() > 0 { + return m.b.ReadByte() + } + return m.br.ReadByte() +} + +func (m *multiByteReader) Read(p []byte) (n int, err error) { + return m.mr.Read(p) +} From 38521caaf3eba2954e5728e6f3df6cf3c350dcad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jun 2023 12:58:02 +0000 Subject: [PATCH 2/4] Bump github.com/pierrec/lz4/v4 from 4.1.17 to 4.1.18 Bumps [github.com/pierrec/lz4/v4](https://github.com/pierrec/lz4) from 4.1.17 to 4.1.18. - [Commits](https://github.com/pierrec/lz4/compare/v4.1.17...v4.1.18) --- updated-dependencies: - dependency-name: github.com/pierrec/lz4/v4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2d787cd..d78fd0b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/bodgit/windows v1.0.1 github.com/hashicorp/go-multierror v1.1.1 github.com/klauspost/compress v1.16.6 - github.com/pierrec/lz4/v4 v4.1.17 + github.com/pierrec/lz4/v4 v4.1.18 github.com/stretchr/testify v1.8.4 github.com/ulikunitz/xz v0.5.11 go4.org v0.0.0-20200411211856-f5505b9728dd diff --git a/go.sum b/go.sum index bc003aa..66b0e4f 100644 --- a/go.sum +++ b/go.sum @@ -77,8 +77,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc= -github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ= +github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= From bebc098e2a51db10d38828e17ec2d5ee32367dcb Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Mon, 3 Jul 2023 11:55:03 +0100 Subject: [PATCH 3/4] Turn off depguard lint check Not sure why it's suddenly started flagging imports. --- .golangci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 3aa13dc..018a766 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -10,7 +10,6 @@ linters: - contextcheck - cyclop - decorder - - depguard - dogsled - dupl - dupword From 68a68545f761d93db5e99748f15ee80e019839a3 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Mon, 3 Jul 2023 12:13:33 +0100 Subject: [PATCH 4/4] Lint fixes --- internal/lzma/reader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lzma/reader.go b/internal/lzma/reader.go index 9f47a2a..485d9f6 100644 --- a/internal/lzma/reader.go +++ b/internal/lzma/reader.go @@ -40,6 +40,7 @@ func NewReader(p []byte, s uint64, readers []io.ReadCloser) (io.ReadCloser, erro h := bytes.NewBuffer(p) _ = binary.Write(h, binary.LittleEndian, s) + lr, err := lzma.NewReader(multiReader(h, readers[0])) if err != nil { return nil, err @@ -53,6 +54,7 @@ func NewReader(p []byte, s uint64, readers []io.ReadCloser) (io.ReadCloser, erro func multiReader(b *bytes.Buffer, rc io.ReadCloser) io.Reader { mr := io.MultiReader(b, rc) + if br, ok := rc.(io.ByteReader); ok { return &multiByteReader{ b: b, @@ -60,6 +62,7 @@ func multiReader(b *bytes.Buffer, rc io.ReadCloser) io.Reader { mr: mr, } } + return mr } @@ -73,6 +76,7 @@ func (m *multiByteReader) ReadByte() (byte, error) { if m.b.Len() > 0 { return m.b.ReadByte() } + return m.br.ReadByte() }