add Close to the reader
This commit is contained in:
parent
8910fced57
commit
01933df053
@ -10,11 +10,11 @@ import (
|
|||||||
type ReadFilter func([]byte, int, error) (int, error)
|
type ReadFilter func([]byte, int, error) (int, error)
|
||||||
|
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
input io.Reader
|
input io.ReadCloser
|
||||||
filter ReadFilter
|
filter ReadFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReader(reader io.Reader, filter ReadFilter) *Reader {
|
func NewReader(reader io.ReadCloser, filter ReadFilter) *Reader {
|
||||||
return &Reader{
|
return &Reader{
|
||||||
input: reader,
|
input: reader,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
@ -30,3 +30,7 @@ func (r *Reader) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Reader) Close() error {
|
||||||
|
return r.input.Close()
|
||||||
|
}
|
||||||
|
@ -6,11 +6,12 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
"strings"
|
"strings"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewReader(t *testing.T) {
|
func TestNewReader(t *testing.T) {
|
||||||
buffer := make([]byte, 20)
|
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"))
|
copy(p, []byte("foo"))
|
||||||
return 3, nil
|
return 3, nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user