github.com/searKing/golang/go@v1.2.117/io/replay.go (about) 1 package io 2 3 import "io" 4 5 // ReadReplayer is the interface that groups the basic Read and Replay methods. 6 type ReadReplayer interface { 7 io.Reader 8 Replay() ReadReplayer 9 } 10 11 // ReplayReader returns a Reader that allows replay and read from 12 // the provided input reader. 13 // data is buffered always. 14 // buffered data is taken first, if Replay() is called. 15 func ReplayReader(r io.Reader) ReadReplayer { 16 sr := &replayReader{ 17 ReadSniffer: SniffReader(r).Sniff(true), 18 } 19 return sr 20 } 21 22 type replayReader struct { 23 ReadSniffer 24 } 25 26 func (r *replayReader) Replay() ReadReplayer { 27 r.Sniff(false).Sniff(true) 28 return r 29 }