File tree 1 file changed +20
-10
lines changed
1 file changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,11 @@ func newBuffer(rd io.Reader) buffer {
34
34
35
35
// fill reads into the buffer until at least _need_ bytes are in it
36
36
func (b * buffer ) fill (need int ) error {
37
+ n := b .length
38
+
37
39
// move existing data to the beginning
38
- if b . length > 0 && b .idx > 0 {
39
- copy (b .buf [0 :b . length ], b .buf [b .idx :])
40
+ if n > 0 && b .idx > 0 {
41
+ copy (b .buf [0 :n ], b .buf [b .idx :])
40
42
}
41
43
42
44
// grow buffer if necessary
@@ -52,19 +54,27 @@ func (b *buffer) fill(need int) error {
52
54
b .idx = 0
53
55
54
56
for {
55
- n , err := b .rd .Read (b .buf [b . length :])
56
- b . length += n
57
+ nn , err := b .rd .Read (b .buf [n :])
58
+ n += nn
57
59
58
- if err == nil {
59
- if b .length < need {
60
+ switch err {
61
+ case nil :
62
+ if n < need {
60
63
continue
61
64
}
65
+ b .length = n
62
66
return nil
67
+
68
+ case io .EOF :
69
+ if n >= need {
70
+ b .length = n
71
+ return nil
72
+ }
73
+ return io .ErrUnexpectedEOF
74
+
75
+ default :
76
+ return err
63
77
}
64
- if b .length >= need && err == io .EOF {
65
- return nil
66
- }
67
- return err
68
78
}
69
79
}
70
80
You can’t perform that action at this time.
0 commit comments