Debian Codegraph @

pool.go

raw symbols SCIP
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 // Pool provides a way to Allocate and Release Buffer objects
13 // Pools mut be concurrent-safe for calls to Get() and Put().
14 type Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool# interface {
15 Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool#Get.() (Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#, error) // Allocate a Buffer
16 Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool#Put.(buf Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#) error // Release or Reuse a Buffer
17 }
18
19 type poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool# struct {
20 poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#pool. 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 // NewPool returns a Pool(), 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 NewPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPool().(New func() Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#) Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool# {
27 return &poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#{
28 poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#pool.: 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 *poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#) Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#Get().() (Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#, error) {
37 return p.poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#pool..Getscip-go gomod github.com/golang/go/src go1.13 sync/Pool#Get().().(Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#), nil
38 }
39
40 func (p *poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#) Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#Put().(buf Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#) error {
41 buf.Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Reset.()
42 p.poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/pool#pool..Putscip-go gomod github.com/golang/go/src go1.13 sync/Pool#Put().(buf)
43 return nil
44 }
45
46 type memPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool# struct {
47 Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#N. int64
48 Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#Pool.
49 }
50
51 // NewMemPool returns a Pool, 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 NewMemPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewMemPool().(N int64) Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool# {
55 return &memPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#{
56 Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#N.: N,
57 Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#Pool.: NewPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPool().(func() Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer# {
58 return Newscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/New().(N)
59 }),
60 }
61 }
62
63 func (m *memPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#) MarshalBinaryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#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`/memPool#N.)
66 return buf.Bytesscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#Bytes().(), err
67 }
68
69 func (m *memPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#) UnmarshalBinaryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#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`/memPool#N.)
72 m.Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#Pool. = NewPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPool().(func() Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer# {
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`/memPool#N.)
74 })
75 return err
76 }
77
78 type filePoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool# struct {
79 Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#N. int64
80 Directoryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#Directory. string
81 }
82
83 // NewFilePool returns a Pool, 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 NewFilePoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewFilePool().(N int64, dir string) Poolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Pool# {
88 return &filePoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#{Nscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#N.: N, Directoryscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#Directory.: dir}
89 }
90
91 func (p *filePoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#) Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#Get().() (Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#, 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`/filePool#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`/filePool#N., file), nil
97 }
98
99 func (p *filePoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#) Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#Put().(buf Bufferscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#) (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().(&memPoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/memPool#{})
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().(&filePoolscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/filePool#{})
111 }