MCPcopy Create free account
hub / github.com/djherbis/buffer / NewSwapAt

Function NewSwapAt

swap.go:27–32  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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().
27func 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
34func (buf *swap) Len() int64 {
35 return buf.A.Len() + buf.B.Len()

Callers 3

NewSwapFunction · 0.85
TestWriteAtFunction · 0.85
TestSwapAtFunction · 0.85

Calls 1

CapMethod · 0.65

Tested by 2

TestWriteAtFunction · 0.68
TestSwapAtFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…