-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_debug.go
71 lines (60 loc) · 1.28 KB
/
io_debug.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
// Copyright © 2021 Nadeen Udantha [email protected]
package boiio
import (
"fmt"
"io"
)
type io_debugRWC struct {
n string
r io.Reader
w io.Writer
c io.Closer
}
func DebugIoReader(name string, r io.Reader) io.Reader {
return &io_debugRWC{
n: name,
r: r,
}
}
func DebugIoWriter(name string, w io.Writer) io.Writer {
return &io_debugRWC{
n: name,
w: w,
}
}
func DebugIoReadWriter(name string, rw io.ReadWriter) io.ReadWriter {
return &io_debugRWC{
n: name,
r: rw,
w: rw,
}
}
func DebugIoReadWriteCloser(name string, rwc io.ReadWriteCloser) io.ReadWriteCloser {
return &io_debugRWC{
n: name,
r: rwc,
w: rwc,
c: rwc,
}
}
func (drw *io_debugRWC) log(format string, a ...interface{}) {
fmt.Printf("debugRWC %s %s\n", drw.n, fmt.Sprintf(format, a...))
}
func (drw *io_debugRWC) Read(p []byte) (int, error) {
drw.log("Read0")
n, err := drw.r.Read(p)
drw.log("Read1 %d %v %v", n, err, p[:n])
return n, err
}
func (drw *io_debugRWC) Write(p []byte) (int, error) {
drw.log("Write0 %v", p)
n, err := drw.w.Write(p)
drw.log("Write1 %d %v %v", n, err, p[:n])
return n, err
}
func (drw *io_debugRWC) Close() error {
drw.log("Close0")
err := drw.c.Close()
drw.log("Close1 %v", err)
return err
}