-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuffer.go
95 lines (73 loc) · 1.17 KB
/
buffer.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package pdf
import (
"bytes"
"fmt"
"io"
)
// stores errors until buffer.WriteTo
type buffer struct {
b *bytes.Buffer
err error
}
func (b *buffer) WriteTo(w io.Writer) (int64, error) {
if b.b == nil {
b.b = &bytes.Buffer{}
}
if b.err != nil {
return 0, b.err
}
return b.b.WriteTo(w)
}
func (b *buffer) WriteString(s string) {
if b.b == nil {
b.b = &bytes.Buffer{}
}
if b.err != nil {
return
}
_, b.err = b.b.WriteString(s)
}
func (b *buffer) Write(p []byte) (int, error) {
if b.b == nil {
b.b = &bytes.Buffer{}
}
if b.err != nil {
return 0, b.err
}
var n int
n, b.err = b.b.Write(p)
return n, b.err
}
func (b *buffer) Printf(format string, a ...interface{}) {
if b.b == nil {
b.b = &bytes.Buffer{}
}
if b.err != nil {
return
}
_, b.err = fmt.Fprintf(b.b, format, a...)
}
func (b *buffer) WriteByte(c byte) {
if b.b == nil {
b.b = &bytes.Buffer{}
}
if b.err != nil {
return
}
b.err = b.b.WriteByte(c)
}
func (b *buffer) Truncate(n int) {
if b.b == nil {
b.b = &bytes.Buffer{}
}
if b.err != nil {
return
}
b.b.Truncate(n)
}
func (b *buffer) Len() int {
if b.b == nil {
b.b = &bytes.Buffer{}
}
return b.b.Len()
}