| 1 | package bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/" |
| 5 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/" |
| 6 | "encoding/gobscip-go gomod github.com/golang/go/src go1.13 `encoding/gob`/" |
| 7 | "io/ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.13 os/" |
| 9 | "syncscip-go gomod github.com/golang/go/src go1.13 sync/" |
| 10 | ) |
| 11 | |
| 12 | // PoolAt provides a way to Allocate and Release BufferAt objects |
| 13 | // PoolAt's mut be concurrent-safe for calls to Get() and Put(). |
| 14 | type PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt# interface { |
| 15 | Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt#Get.() (BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#, error) // Allocate a BufferAt |
| 16 | Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt#Put.(buf BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#) error // Release or Reuse a BufferAt |
| 17 | } |
| 18 | |
| 19 | type poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt# struct { |
| 20 | poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#poolAt. syncscip-go gomod github.com/golang/go/src go1.13 sync/.Poolscip-go gomod github.com/golang/go/src go1.13 sync/Pool# |
| 21 | } |
| 22 | |
| 23 | // NewPoolAt returns a PoolAt(), it's backed by a sync.Pool so its safe for concurrent use. |
| 24 | // Get() and Put() errors will always be nil. |
| 25 | // It will not work with gob. |
| 26 | func NewPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPoolAt().(New func() BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#) PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt# { |
| 27 | return &poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#{ |
| 28 | poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#poolAt.: syncscip-go gomod github.com/golang/go/src go1.13 sync/.Poolscip-go gomod github.com/golang/go/src go1.13 sync/Pool#{ |
| 29 | Newscip-go gomod github.com/golang/go/src go1.13 sync/Pool#New.: func() interface{} { |
| 30 | return New() |
| 31 | }, |
| 32 | }, |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func (p *poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#) Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#Get().() (BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#, error) { |
| 37 | return p.poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#poolAt..Getscip-go gomod github.com/golang/go/src go1.13 sync/Pool#Get().().(BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#), nil |
| 38 | } |
| 39 | |
| 40 | func (p *poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#) Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#Put().(buf BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#) error { |
| 41 | buf.Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Reset.() |
| 42 | p.poolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/poolAt#poolAt..Putscip-go gomod github.com/golang/go/src go1.13 sync/Pool#Put().(buf) |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | type memPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt# struct { |
| 47 | Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#N. int64 |
| 48 | PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#PoolAt. |
| 49 | } |
| 50 | |
| 51 | // NewMemPoolAt returns a PoolAt, Get() returns an in memory buffer of max size N. |
| 52 | // Put() returns the buffer to the pool after resetting it. |
| 53 | // Get() and Put() errors will always be nil. |
| 54 | func NewMemPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewMemPoolAt().(N int64) PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt# { |
| 55 | return &memPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#{ |
| 56 | Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#N.: N, |
| 57 | PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#PoolAt.: NewPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPoolAt().(func() BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt# { |
| 58 | return Newscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/New().(N) |
| 59 | }), |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func (m *memPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#) MarshalBinaryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#MarshalBinary().() ([]byte, error) { |
| 64 | buf := bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.13 bytes/NewBuffer().(nil) |
| 65 | err := binaryscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/.Writescip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/Write().(buf, binaryscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/LittleEndian., m.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#N.) |
| 66 | return buf.Bytesscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#Bytes().(), err |
| 67 | } |
| 68 | |
| 69 | func (m *memPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#) UnmarshalBinaryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#UnmarshalBinary().(data []byte) error { |
| 70 | buf := bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.13 bytes/NewReader().(data) |
| 71 | err := binaryscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/.Readscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/Read().(buf, binaryscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.13 `encoding/binary`/LittleEndian., &m.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#N.) |
| 72 | m.PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#PoolAt. = NewPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPoolAt().(func() BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt# { |
| 73 | return Newscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/New().(m.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#N.) |
| 74 | }) |
| 75 | return err |
| 76 | } |
| 77 | |
| 78 | type filePoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt# struct { |
| 79 | Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#N. int64 |
| 80 | Directoryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#Directory. string |
| 81 | } |
| 82 | |
| 83 | // NewFilePoolAt returns a PoolAt, Get() returns a file-based buffer of max size N. |
| 84 | // Put() closes and deletes the underlying file for the buffer. |
| 85 | // Get() may return an error if it fails to create a file for the buffer. |
| 86 | // Put() may return an error if it fails to delete the file. |
| 87 | func NewFilePoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewFilePoolAt().(N int64, dir string) PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt# { |
| 88 | return &filePoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#{Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#N.: N, Directoryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#Directory.: dir} |
| 89 | } |
| 90 | |
| 91 | func (p *filePoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#) Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#Get().() (BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#, error) { |
| 92 | file, err := ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.TempFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/TempFile().(p.Directoryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#Directory., "buffer") |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | return NewFilescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewFile().(p.Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#N., file), nil |
| 97 | } |
| 98 | |
| 99 | func (p *filePoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#) Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#Put().(buf BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#) (err error) { |
| 100 | buf.Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Reset.() |
| 101 | if fileBuf, ok := buf.(*fileBufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/fileBuffer#); ok { |
| 102 | fileBuf.filescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/fileBuffer#file..Closescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/File#Close.() |
| 103 | err = osscip-go gomod github.com/golang/go/src go1.13 os/.Removescip-go gomod github.com/golang/go/src go1.13 os/Remove().(fileBuf.filescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/fileBuffer#file..Namescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/File#Name.()) |
| 104 | } |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | func initscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/init().() { |
| 109 | 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().(&memPoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPoolAt#{}) |
| 110 | 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().(&filePoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePoolAt#{}) |
| 111 | } |