github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/topic/topicreaderinternal/one_time_reader.go (about) 1 package topicreaderinternal 2 3 import ( 4 "io" 5 ) 6 7 type oneTimeReader struct { 8 err error 9 reader io.Reader 10 } 11 12 func newOneTimeReader(reader io.Reader) oneTimeReader { 13 return oneTimeReader{ 14 reader: reader, 15 } 16 } 17 18 func (s *oneTimeReader) Read(p []byte) (n int, err error) { 19 if s.err != nil { 20 return 0, s.err 21 } 22 23 n, err = s.reader.Read(p) 24 25 if err != nil { 26 s.err = err 27 s.reader = nil 28 } 29 30 return n, err 31 }