| 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 | "mathscip-go gomod github.com/golang/go/src go1.13 math/" |
| 7 | ) |
| 8 | |
| 9 | type partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition# struct { |
| 10 | Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List. |
| 11 | Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Pool. |
| 12 | } |
| 13 | |
| 14 | // NewPartition returns a Buffer which uses a Pool to extend or shrink its size as needed. |
| 15 | // It automatically allocates new buffers with pool.Get() to extend is length, and |
| 16 | // pool.Put() to release unused buffers as it shrinks. |
| 17 | func NewPartitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPartition().(pool Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool#, buffers ...Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#) Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer# { |
| 18 | return &partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#{ |
| 19 | Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Pool.: pool, |
| 20 | Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.: buffers, |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func (buf *partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#) Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Cap().() int64 { |
| 25 | return mathscip-go gomod github.com/golang/go/src go1.13 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.13 math/MaxInt64. |
| 26 | } |
| 27 | |
| 28 | func (buf *partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#) Readscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Read().(p []byte) (n int, err error) { |
| 29 | for len(p) > 0 { |
| 30 | |
| 31 | if len(buf.Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.) == 0 { |
| 32 | return n, ioscip-go gomod github.com/golang/go/src go1.13 io/.EOFscip-go gomod github.com/golang/go/src go1.13 io/EOF. |
| 33 | } |
| 34 | |
| 35 | buffer := buf.Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.[0] |
| 36 | |
| 37 | if Emptyscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Empty().(buffer) { |
| 38 | buf.Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Pool..Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool#Put.(buf.Popscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/List#Pop().()) |
| 39 | continue |
| 40 | } |
| 41 | |
| 42 | m, er := buffer.Readscip-go gomod github.com/golang/go/src go1.13 io/Reader#Read().(p) |
| 43 | n += m |
| 44 | p = p[m:] |
| 45 | |
| 46 | if er != nil && er != ioscip-go gomod github.com/golang/go/src go1.13 io/.EOFscip-go gomod github.com/golang/go/src go1.13 io/EOF. { |
| 47 | return n, er |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | return n, nil |
| 52 | } |
| 53 | |
| 54 | func (buf *partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#) growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#grow().() error { |
| 55 | next, err := buf.Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Pool..Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool#Get.() |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | buf.Pushscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/List#Push().(next) |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | func (buf *partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#) Writescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Write().(p []byte) (n int, err error) { |
| 64 | for len(p) > 0 { |
| 65 | |
| 66 | if len(buf.Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.) == 0 { |
| 67 | if err := buf.growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#grow().(); err != nil { |
| 68 | return n, err |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | buffer := buf.Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.[len(buf.Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.)-1] |
| 73 | |
| 74 | if Fullscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Full().(buffer) { |
| 75 | if err := buf.growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#grow().(); err != nil { |
| 76 | return n, err |
| 77 | } |
| 78 | continue |
| 79 | } |
| 80 | |
| 81 | m, er := buffer.Writescip-go gomod github.com/golang/go/src go1.13 io/Writer#Write().(p) |
| 82 | n += m |
| 83 | p = p[m:] |
| 84 | |
| 85 | if er != nil && er != ioscip-go gomod github.com/golang/go/src go1.13 io/.ErrShortWritescip-go gomod github.com/golang/go/src go1.13 io/ErrShortWrite. { |
| 86 | return n, er |
| 87 | } |
| 88 | |
| 89 | } |
| 90 | return n, nil |
| 91 | } |
| 92 | |
| 93 | func (buf *partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#) Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Reset().() { |
| 94 | for len(buf.Listscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#List.) > 0 { |
| 95 | buf.Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#Pool..Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool#Put.(buf.Popscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/List#Pop().()) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func initscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/init().() { |
| 100 | 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().(&partitionscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partition#{}) |
| 101 | } |