Skip to content

Commit

Permalink
Remove mutex
Browse files Browse the repository at this point in the history
Not sure it was doing anything useful. Make the passed reader implement
io.ByteReader.
  • Loading branch information
bodgit committed May 10, 2022
1 parent 14bacd7 commit cf56a3c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions internal/deflate/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"io"
"sync"

"github.com/bodgit/sevenzip/internal/util"
)

//nolint:gochecknoglobals
Expand All @@ -13,13 +15,9 @@ var flateReaderPool sync.Pool
type readCloser struct {
c io.Closer
fr io.ReadCloser
mu sync.Mutex
}

func (rc *readCloser) Close() error {
rc.mu.Lock()
defer rc.mu.Unlock()

var err error

if rc.c != nil {
Expand All @@ -36,9 +34,6 @@ func (rc *readCloser) Close() error {
}

func (rc *readCloser) Read(p []byte) (int, error) {
rc.mu.Lock()
defer rc.mu.Unlock()

if rc.fr == nil {
return 0, errors.New("deflate: Read after Close")
}
Expand All @@ -56,12 +51,12 @@ func NewReader(_ []byte, _ uint64, readers []io.ReadCloser) (io.ReadCloser, erro
if ok {
frf, ok := fr.(flate.Resetter)
if ok {
if err := frf.Reset(readers[0], nil); err != nil {
if err := frf.Reset(util.ByteReadCloser(readers[0]), nil); err != nil {
return nil, err
}
}
} else {
fr = flate.NewReader(readers[0])
fr = flate.NewReader(util.ByteReadCloser(readers[0]))
}

return &readCloser{
Expand Down

0 comments on commit cf56a3c

Please sign in to comment.