Debian Codegraph @

partition_at.go

raw symbols SCIP
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 "errorsscip-go gomod github.com/golang/go/src go1.13 errors/"
6 "ioscip-go gomod github.com/golang/go/src go1.13 io/"
7 "mathscip-go gomod github.com/golang/go/src go1.13 math/"
8 )
9
10 type partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt# struct {
11 ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.
12 PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#PoolAt.
13 }
14
15 // NewPartitionAt returns a BufferAt which uses a PoolAt to extend or shrink its size as needed.
16 // It automatically allocates new buffers with pool.Get() to extend is length, and
17 // pool.Put() to release unused buffers as it shrinks.
18 func NewPartitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/NewPartitionAt().(pool PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt#, buffers ...BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#) BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt# {
19 return &partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#{
20 PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#PoolAt.: pool,
21 ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.: buffers,
22 }
23 }
24
25 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#Cap().() int64 {
26 return mathscip-go gomod github.com/golang/go/src go1.13 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.13 math/MaxInt64.
27 }
28
29 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) Readscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#Read().(p []byte) (n int, err error) {
30 for len(p) > 0 {
31
32 if len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.) == 0 {
33 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.
34 }
35
36 buffer := buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.[0]
37
38 if Emptyscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Empty().(buffer) {
39 buf.PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#PoolAt..Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt#Put.(buf.Popscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/ListAt#Pop().())
40 continue
41 }
42
43 m, er := buffer.Readscip-go gomod github.com/golang/go/src go1.13 io/Reader#Read().(p)
44 n += m
45 p = p[m:]
46
47 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. {
48 return n, er
49 }
50
51 }
52 return n, nil
53 }
54
55 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) ReadAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ReadAt().(p []byte, off int64) (n int, err error) {
56 if off < 0 {
57 return 0, errorsscip-go gomod github.com/golang/go/src go1.13 errors/.Newscip-go gomod github.com/golang/go/src go1.13 errors/New().("buffer.PartionAt.ReadAt: negative offset")
58 }
59 for _, buffer := range buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt. {
60 // Find the buffer where this offset is found.
61 if buffer.Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.() <= off {
62 off -= buffer.Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.()
63 continue
64 }
65
66 m, er := buffer.ReadAtscip-go gomod github.com/golang/go/src go1.13 io/ReaderAt#ReadAt().(p, off)
67 n += m
68 p = p[m:]
69
70 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. {
71 return n, er
72 }
73 if len(p) == 0 {
74 return n, er
75 }
76 // We need to read more, starting from 0 in the next buffer.
77 off = 0
78 }
79 if len(p) > 0 {
80 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.
81 }
82 return n, nil
83 }
84
85 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#grow().() error {
86 next, err := buf.PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#PoolAt..Getscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt#Get.()
87 if err != nil {
88 return err
89 }
90 buf.Pushscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/ListAt#Push().(next)
91 return nil
92 }
93
94 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) Writescip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#Write().(p []byte) (n int, err error) {
95 for len(p) > 0 {
96
97 if len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.) == 0 {
98 if err := buf.growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#grow().(); err != nil {
99 return n, err
100 }
101 }
102
103 buffer := buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.[len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.)-1]
104
105 if Fullscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Full().(buffer) {
106 if err := buf.growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#grow().(); err != nil {
107 return n, err
108 }
109 continue
110 }
111
112 m, er := buffer.Writescip-go gomod github.com/golang/go/src go1.13 io/Writer#Write().(p)
113 n += m
114 p = p[m:]
115
116 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. {
117 return n, er
118 }
119
120 }
121 return n, nil
122 }
123
124 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) WriteAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#WriteAt().(p []byte, off int64) (n int, err error) {
125 if off < 0 {
126 return 0, errorsscip-go gomod github.com/golang/go/src go1.13 errors/.Newscip-go gomod github.com/golang/go/src go1.13 errors/New().("buffer.PartionAt.WriteAt: negative offset")
127 }
128 if off == buf.Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/ListAt#Len().() { // writing at the end special case
129 if err := buf.growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#grow().(); err != nil {
130 return 0, err
131 }
132 }
133 fitCheck := BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#.Lenscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Len.
134 for i := 0; i < len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.); i++ {
135 buffer := buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.[i]
136
137 // Find the buffer where this offset is found.
138 if fitCheck(buffer) < off {
139 off -= fitCheck(buffer)
140 continue
141 }
142
143 if i+1 == len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.) {
144 fitCheck = BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#.Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.
145 }
146
147 endOff := off + int64(len(p))
148 if fitCheck(buffer) >= endOff {
149 // Everything should fit.
150 return buffer.WriteAtscip-go gomod github.com/golang/go/src go1.13 io/WriterAt#WriteAt().(p, off)
151 }
152
153 // Assume it won't all fit, only write what should fit.
154 canFit := int(fitCheck(buffer) - off)
155 if len(p[:canFit]) > 0 {
156 var m int
157 m, err = buffer.WriteAtscip-go gomod github.com/golang/go/src go1.13 io/WriterAt#WriteAt().(p[:canFit], off)
158 n += m
159 p = p[m:]
160 }
161 off = 0 // All writes are at offset 0 of following buffers now.
162
163 if err != nil || len(p) == 0 {
164 return n, err
165 }
166 if i+1 == len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.) {
167 if err := buf.growscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#grow().(); err != nil {
168 return 0, err
169 }
170 fitCheck = BufferAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/BufferAt#.Capscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/Buffer#Cap.
171 }
172 }
173 if len(p) > 0 {
174 err = ioscip-go gomod github.com/golang/go/src go1.13 io/.ErrShortWritescip-go gomod github.com/golang/go/src go1.13 io/ErrShortWrite.
175 }
176 return n, err
177 }
178
179 func (buf *partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#) Resetscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#Reset().() {
180 for len(buf.ListAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#ListAt.) > 0 {
181 buf.PoolAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#PoolAt..Putscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/PoolAt#Put.(buf.Popscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/ListAt#Pop().())
182 }
183 }
184
185 func initscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/init().() {
186 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().(&partitionAtscip-go gomod github.com/djherbis/buffer . `github.com/djherbis/buffer`/partitionAt#{})
187 }