-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.go
55 lines (42 loc) · 914 Bytes
/
io.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
package xo
import (
"bytes"
"io"
"os"
)
// ReadFileAsBytesBuffer reads a file and returns a bytes.Buffer.
func ReadFileAsBytesBuffer(path string) (*bytes.Buffer, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, file)
if err != nil {
return nil, err
}
return buf, nil
}
type NopIoWriter struct{}
type EmptyIoWriter = NopIoWriter
func NewNopIoWriter() *NopIoWriter {
return &NopIoWriter{}
}
func NewEmptyIoWriter() *NopIoWriter {
return &NopIoWriter{}
}
func (w *NopIoWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
type NopIoReader struct{}
type EmptyIoReader = NopIoReader
func NewNopIoReader() *NopIoReader {
return &NopIoReader{}
}
func NewEmptyIoReader() *NopIoReader {
return &NopIoReader{}
}
func (r *NopIoReader) Read(p []byte) (n int, err error) {
return 0, io.EOF
}