diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..1f3d05a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,46 @@ +name: build-test + +on: [push] + +jobs: + test: + name: build-test + strategy: + fail-fast: false + matrix: + go-version: [1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Build + run: | + go env -w GOFLAGS=-mod=mod + go build -v ./... + + - name: Test With Coverage + run: go test -race -coverprofile=coverage -covermode=atomic + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + files: ./coverage + if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x' + + - name: Go vet + run: | + go vet . + if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x' + + - name: Go Static Check + run: | + go install honnef.co/go/tools/cmd/staticcheck@latest + staticcheck . + if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x' diff --git a/filestream.go b/filestream.go index 812df04..039d3c0 100644 --- a/filestream.go +++ b/filestream.go @@ -16,6 +16,7 @@ type FileStream struct { info os.FileInfo f *os.File bs *ByteStream + data mmap.MMap } // Assert interface implementation checks @@ -48,6 +49,7 @@ func NewFileStream(filename string) (*FileStream, error) { info: info, f: f, bs: bs, + data: data, }, nil } @@ -111,5 +113,8 @@ func (fs *FileStream) IsEOF() bool { // Close underlying filestream. func (fs *FileStream) Close() error { + if fs.data != nil { + _ = fs.data.Unmap() + } return fs.f.Close() } diff --git a/go.mod b/go.mod index cffa91e..ca5053a 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/saferwall/binstream go 1.15 require ( - github.com/edsrzf/mmap-go v1.0.0 - golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d // indirect + github.com/edsrzf/mmap-go v1.1.0 + golang.org/x/sys v0.21.0 // indirect ) diff --git a/go.sum b/go.sum index 05ae971..8ce8eb1 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ -github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= -github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= -golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d h1:jbzgAvDZn8aEnytae+4ou0J0GwFZoHR0hOrTg4qH8GA= -golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ= +github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=