From 01933df053df37f0c6c72684f46ac66fa66366ae Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Thu, 19 Sep 2024 08:18:48 +0000 Subject: [PATCH] add Close to the reader --- internal/iofilter/filter.go | 8 ++++++-- internal/iofilter/filter_test.go | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/iofilter/filter.go b/internal/iofilter/filter.go index 4316bb5..fcdcc8f 100644 --- a/internal/iofilter/filter.go +++ b/internal/iofilter/filter.go @@ -10,11 +10,11 @@ import ( type ReadFilter func([]byte, int, error) (int, error) type Reader struct { - input io.Reader + input io.ReadCloser filter ReadFilter } -func NewReader(reader io.Reader, filter ReadFilter) *Reader { +func NewReader(reader io.ReadCloser, filter ReadFilter) *Reader { return &Reader{ input: reader, filter: filter, @@ -30,3 +30,7 @@ func (r *Reader) Read(p []byte) (n int, err error) { } return n, err } + +func (r *Reader) Close() error { + return r.input.Close() +} diff --git a/internal/iofilter/filter_test.go b/internal/iofilter/filter_test.go index f1cf307..3e7b50c 100644 --- a/internal/iofilter/filter_test.go +++ b/internal/iofilter/filter_test.go @@ -6,11 +6,12 @@ import ( "github.com/stretchr/testify/assert" "testing" "strings" + "io" ) func TestNewReader(t *testing.T) { buffer := make([]byte, 20) - reader := NewReader(strings.NewReader("testdata"), func(p []byte, in int, e error) (int, error) { + reader := NewReader(io.NopCloser(strings.NewReader("testdata")), func(p []byte, in int, e error) (int, error) { copy(p, []byte("foo")) return 3, nil })