reader.go (692B)
1 package byteutil 2 3 import "bytes" 4 5 // Reader wraps a bytes.Reader{} to provide Rewind() capabilities. 6 type Reader struct { 7 B []byte 8 bytes.Reader 9 } 10 11 // NewReader returns a new Reader{} instance reset to b. 12 func NewReader(b []byte) *Reader { 13 r := &Reader{} 14 r.Reset(b) 15 return r 16 } 17 18 // Reset resets the Reader{} to be reading from b and sets Reader{}.B. 19 func (r *Reader) Reset(b []byte) { 20 r.B = b 21 r.Rewind() 22 } 23 24 // Rewind resets the Reader{} to be reading from the start of Reader{}.B. 25 func (r *Reader) Rewind() { 26 r.Reader.Reset(r.B) 27 } 28 29 // ReadNopCloser wraps a Reader{} to provide nop close method. 30 type ReadNopCloser struct { 31 Reader 32 } 33 34 func (*ReadNopCloser) Close() error { 35 return nil 36 }