-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.go
43 lines (39 loc) · 761 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
package extremofile
// Here be file IO routines.
import (
"io/ioutil"
"os"
)
func fileRead(path string) ([]byte, error) {
f, err := os.Open(path)
if f != nil {
defer f.Close()
}
if err != nil {
return nil, err
}
var rdata []byte
rdata, err = ioutil.ReadAll(f)
if err != nil {
return nil, err
}
return rdata, nil
}
func fileWrite(path string, perm os.FileMode, data []byte) error {
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, perm)
if f != nil {
// Ignore Close() error, check full read later.
defer f.Close()
}
if err != nil {
return err
}
// Ignore number of bytes written, check full read later.
if _, err = f.Write(data); err != nil {
return err
}
if err = f.Sync(); err != nil {
return err
}
return nil
}