-
Notifications
You must be signed in to change notification settings - Fork 67
/
io_writer.go
51 lines (41 loc) · 830 Bytes
/
io_writer.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
package core
import (
"io"
"unsafe"
)
type (
IOWriter struct {
io.Writer
hash uint32
}
)
func MakeIOWriter(w io.Writer) *IOWriter {
res := &IOWriter{w, 0}
res.hash = HashPtr(uintptr(unsafe.Pointer(res)))
return res
}
func (iow *IOWriter) ToString(escape bool) string {
return "#object[IOWriter]"
}
func (iow *IOWriter) Equals(other interface{}) bool {
return iow == other
}
func (iow *IOWriter) GetInfo() *ObjectInfo {
return nil
}
func (iow *IOWriter) GetType() *Type {
return TYPE.IOWriter
}
func (iow *IOWriter) Hash() uint32 {
return iow.hash
}
func (iow *IOWriter) WithInfo(info *ObjectInfo) Object {
return iow
}
func (iow *IOWriter) Close() error {
if c, ok := iow.Writer.(io.Closer); ok {
return c.Close()
} else {
return RT.NewError("Object is not closable: " + iow.ToString(false))
}
}