| 1 | package bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/gobscip-go gomod github.com/golang/go/src go1.13 `encoding/gob`/" |
| 5 | "ioscip-go gomod github.com/golang/go/src go1.13 io/" |
| 6 | ) |
| 7 | |
| 8 | type swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap# struct { |
| 9 | Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A. BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt# |
| 10 | Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B. BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt# |
| 11 | } |
| 12 | |
| 13 | // NewSwap creates a Buffer which writes to a until you write past a.Cap() |
| 14 | // then it io.Copy's from a to b and writes to b. |
| 15 | // Once the Buffer is empty again, it starts over writing to a. |
| 16 | // Note that if b.Cap() <= a.Cap() it will cause a panic, b is expected |
| 17 | // to be larger in order to accommodate writes past a.Cap(). |
| 18 | func NewSwapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewSwap().(a, b Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#) Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer# { |
| 19 | return NewSwapAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewSwapAt().(toBufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/toBufferAt().(a), toBufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/toBufferAt().(b)) |
| 20 | } |
| 21 | |
| 22 | // NewSwapAt creates a BufferAt which writes to a until you write past a.Cap() |
| 23 | // then it io.Copy's from a to b and writes to b. |
| 24 | // Once the Buffer is empty again, it starts over writing to a. |
| 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 NewSwapAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewSwapAt().(a, b BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#) BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt# { |
| 28 | if b.Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.() <= a.Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.() { |
| 29 | panic("Buffer b must be larger than a.") |
| 30 | } |
| 31 | return &swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#{Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A.: a, Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B.: b} |
| 32 | } |
| 33 | |
| 34 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#Len().() int64 { |
| 35 | return buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() + buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() |
| 36 | } |
| 37 | |
| 38 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#Cap().() int64 { |
| 39 | return buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.() |
| 40 | } |
| 41 | |
| 42 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) Readscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#Read().(p []byte) (n int, err error) { |
| 43 | if buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() > 0 { |
| 44 | return buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Readscip-go gomod github.com/golang/go/src go1.13 io/Reader#Read().(p) |
| 45 | } |
| 46 | return buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Readscip-go gomod github.com/golang/go/src go1.13 io/Reader#Read().(p) |
| 47 | } |
| 48 | |
| 49 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) ReadAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#ReadAt().(p []byte, off int64) (n int, err error) { |
| 50 | if buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() > 0 { |
| 51 | return buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..ReadAtscip-go gomod github.com/golang/go/src go1.13 io/ReaderAt#ReadAt().(p, off) |
| 52 | } |
| 53 | return buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..ReadAtscip-go gomod github.com/golang/go/src go1.13 io/ReaderAt#ReadAt().(p, off) |
| 54 | } |
| 55 | |
| 56 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) Writescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#Write().(p []byte) (n int, err error) { |
| 57 | switch { |
| 58 | case buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() > 0: |
| 59 | n, err = buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Writescip-go gomod github.com/golang/go/src go1.13 io/Writer#Write().(p) |
| 60 | |
| 61 | case buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.()+int64(len(p)) > buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.(): |
| 62 | _, err = ioscip-go gomod github.com/golang/go/src go1.13 io/.Copyscip-go gomod github.com/golang/go/src go1.13 io/Copy().(buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B., buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A.) |
| 63 | if err == nil { |
| 64 | n, err = buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Writescip-go gomod github.com/golang/go/src go1.13 io/Writer#Write().(p) |
| 65 | } |
| 66 | |
| 67 | default: |
| 68 | n, err = buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Writescip-go gomod github.com/golang/go/src go1.13 io/Writer#Write().(p) |
| 69 | } |
| 70 | |
| 71 | return n, err |
| 72 | } |
| 73 | |
| 74 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) WriteAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#WriteAt().(p []byte, off int64) (n int, err error) { |
| 75 | switch { |
| 76 | case buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() > 0: |
| 77 | n, err = buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..WriteAtscip-go gomod github.com/golang/go/src go1.13 io/WriterAt#WriteAt().(p, off) |
| 78 | |
| 79 | case off+int64(len(p)) > buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.(): |
| 80 | _, err = ioscip-go gomod github.com/golang/go/src go1.13 io/.Copyscip-go gomod github.com/golang/go/src go1.13 io/Copy().(buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B., buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A.) |
| 81 | if err == nil { |
| 82 | n, err = buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..WriteAtscip-go gomod github.com/golang/go/src go1.13 io/WriterAt#WriteAt().(p, off) |
| 83 | } |
| 84 | |
| 85 | default: |
| 86 | n, err = buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..WriteAtscip-go gomod github.com/golang/go/src go1.13 io/WriterAt#WriteAt().(p, off) |
| 87 | } |
| 88 | |
| 89 | return n, err |
| 90 | } |
| 91 | |
| 92 | func (buf *swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#) Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#Reset().() { |
| 93 | buf.Ascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#A..Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Reset.() |
| 94 | buf.Bscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#B..Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Reset.() |
| 95 | } |
| 96 | |
| 97 | func initscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/init().() { |
| 98 | gobscip-go gomod github.com/golang/go/src go1.13 `encoding/gob`/.Registerscip-go gomod github.com/golang/go/src go1.13 `encoding/gob`/Register().(&swapscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/swap#{}) |
| 99 | } |