-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathbuff.go
More file actions
42 lines (36 loc) · 690 Bytes
/
buff.go
File metadata and controls
42 lines (36 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package gopdf
// Buff for pdf content
type Buff struct {
position int
datas []byte
}
// Write : write []byte to buffer
func (b *Buff) Write(p []byte) (int, error) {
for len(b.datas) < b.position+len(p) {
b.datas = append(b.datas, 0)
}
i := 0
max := len(p)
for i < max {
b.datas[i+b.position] = p[i]
i++
}
b.position += i
return 0, nil
}
// Len : len of buffer
func (b *Buff) Len() int {
return len(b.datas)
}
// Bytes : get bytes
func (b *Buff) Bytes() []byte {
return b.datas
}
// Position : get current position
func (b *Buff) Position() int {
return b.position
}
// SetPosition : set current position
func (b *Buff) SetPosition(pos int) {
b.position = pos
}