| 1 | package wrapioscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/ |
| 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 | "github.com/djherbis/buffer/limioscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/limio`/" |
| 8 | ) |
| 9 | |
| 10 | // ReadWriterAt implements io.ReaderAt and io.WriterAt |
| 11 | type ReadWriterAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/ReadWriterAt# interface { |
| 12 | ioscip-go gomod github.com/golang/go/src go1.13 io/.ReaderAtscip-go gomod github.com/golang/go/src go1.13 io/ReaderAt# |
| 13 | ioscip-go gomod github.com/golang/go/src go1.13 io/.WriterAtscip-go gomod github.com/golang/go/src go1.13 io/WriterAt# |
| 14 | } |
| 15 | |
| 16 | // Wrapper implements a io.ReadWriter and ReadWriterAt such that |
| 17 | // when reading/writing goes past N bytes, it "wraps" back to the beginning. |
| 18 | type Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper# struct { |
| 19 | // N is the offset at which to "wrap" back to the start |
| 20 | Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N. int64 |
| 21 | // L is the length of the data written |
| 22 | Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L. int64 |
| 23 | // O is our offset in the data |
| 24 | Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O. int64 |
| 25 | rwascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#rwa. ReadWriterAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/ReadWriterAt# |
| 26 | } |
| 27 | |
| 28 | // NewWrapper creates a Wrapper based on ReadWriterAt rwa. |
| 29 | // L is the current length, O is the current offset, and N is offset at which we "wrap". |
| 30 | func NewWrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/NewWrapper().(rwa ReadWriterAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/ReadWriterAt#, L, O, N int64) *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper# { |
| 31 | return &Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#{ |
| 32 | Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L.: L, |
| 33 | Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O.: O, |
| 34 | Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N.: N, |
| 35 | rwascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#rwa.: rwa, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Len returns the # of bytes in the Wrapper |
| 40 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#Len().() int64 { |
| 41 | return wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L. |
| 42 | } |
| 43 | |
| 44 | // Cap returns the "wrap" offset (max # of bytes) |
| 45 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#Cap().() int64 { |
| 46 | return wpr.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N. |
| 47 | } |
| 48 | |
| 49 | // Reset seeks to the start (0 offset), and sets the length to 0. |
| 50 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#Reset().() { |
| 51 | wpr.Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O. = 0 |
| 52 | wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L. = 0 |
| 53 | } |
| 54 | |
| 55 | // SetReadWriterAt lets you switch the underlying Read/WriterAt |
| 56 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) SetReadWriterAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#SetReadWriterAt().(rwa ReadWriterAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/ReadWriterAt#) { |
| 57 | wpr.rwascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#rwa. = rwa |
| 58 | } |
| 59 | |
| 60 | // Read reads from the current offset into p, wrapping at Cap() |
| 61 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) Readscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#Read().(p []byte) (n int, err error) { |
| 62 | n, err = wpr.ReadAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#ReadAt().(p, 0) |
| 63 | wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L. -= int64(n) |
| 64 | wpr.Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O. += int64(n) |
| 65 | wpr.Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O. %= wpr.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N. |
| 66 | return n, err |
| 67 | } |
| 68 | |
| 69 | // ReadAt reads from the current offset+off into p, wrapping at Cap() |
| 70 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) ReadAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#ReadAt().(p []byte, off int64) (n int, err error) { |
| 71 | wrap := NewWrapReaderscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/NewWrapReader().(wpr.rwascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#rwa., wpr.Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O.+off, wpr.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N.) |
| 72 | r := ioscip-go gomod github.com/golang/go/src go1.13 io/.LimitReaderscip-go gomod github.com/golang/go/src go1.13 io/LimitReader().(wrap, wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L.-off) |
| 73 | return r.Readscip-go gomod github.com/golang/go/src go1.13 io/Reader#Read().(p) |
| 74 | } |
| 75 | |
| 76 | // Write writes p to the end of the Wrapper (at Len()), wrapping at Cap() |
| 77 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) Writescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#Write().(p []byte) (n int, err error) { |
| 78 | return wpr.WriteAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#WriteAt().(p, wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L.) |
| 79 | } |
| 80 | |
| 81 | // WriteAt writes p at the current offset+off, wrapping at Cap() |
| 82 | func (wpr *Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#) WriteAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#WriteAt().(p []byte, off int64) (n int, err error) { |
| 83 | wrap := NewWrapWriterscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/NewWrapWriter().(wpr.rwascip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#rwa., wpr.Oscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#O.+off, wpr.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N.) |
| 84 | w := limioscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/limio`/.LimitWriterscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/limio`/LimitWriter().(wrap, wpr.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#N.-off) |
| 85 | n, err = w.Writescip-go gomod github.com/golang/go/src go1.13 io/Writer#Write().(p) |
| 86 | if wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L. < off+int64(n) { |
| 87 | wpr.Lscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#L. = int64(n) + off |
| 88 | } |
| 89 | return n, err |
| 90 | } |
| 91 | |
| 92 | func initscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/init().() { |
| 93 | 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().(&Wrapperscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer/wrapio`/Wrapper#{}) |
| 94 | } |