forked from andeya/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap.go
53 lines (44 loc) · 846 Bytes
/
wrap.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
package utils
import (
"io"
)
// WriterWrap writer wrapper
type WriterWrap struct {
w io.Writer
count int
}
// Write writes bytes.
func (wp *WriterWrap) Write(p []byte) (int, error) {
n, err := wp.w.Write(p)
wp.count += n
return n, err
}
// Writed returns writed bytes length.
func (wp *WriterWrap) Writed() int {
return wp.count
}
// Reset resets itself.
func (wp *WriterWrap) Reset(w io.Writer) {
wp.w = w
wp.count = 0
}
// ReaderWrap reader wrapper
type ReaderWrap struct {
r io.Reader
count int
}
// Read reads bytes.
func (rp *ReaderWrap) Read(p []byte) (int, error) {
n, err := rp.r.Read(p)
rp.count += n
return n, err
}
// Readed returns readed bytes length.
func (rp *ReaderWrap) Readed() int {
return rp.count
}
// Reset resets itself.
func (rp *ReaderWrap) Reset(r io.Reader) {
rp.r = r
rp.count = 0
}