NewSwapAt creates a BufferAt which writes to a until you write past a.Cap() then it io.Copy's from a to b and writes to b. Once the Buffer is empty again, it starts over writing to a. Note that if b.Cap() <= a.Cap() it will cause a panic, b is expected to be larger in order to accommodate writes pas
(a, b BufferAt)
| 25 | // Note that if b.Cap() <= a.Cap() it will cause a panic, b is expected |
| 26 | // to be larger in order to accommodate writes past a.Cap(). |
| 27 | func NewSwapAt(a, b BufferAt) BufferAt { |
| 28 | if b.Cap() <= a.Cap() { |
| 29 | panic("Buffer b must be larger than a.") |
| 30 | } |
| 31 | return &swap{A: a, B: b} |
| 32 | } |
| 33 | |
| 34 | func (buf *swap) Len() int64 { |
| 35 | return buf.A.Len() + buf.B.Len() |
searching dependent graphs…