-
Notifications
You must be signed in to change notification settings - Fork 1
/
io_utils.go
63 lines (44 loc) · 836 Bytes
/
io_utils.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
package ks
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
)
func ReadBytesFromFile(filename string) ([]byte, error) {
fin, err := os.Open(filename)
if err != nil {
return nil, err
}
return ioutil.ReadAll(fin)
}
func ReadLines(r io.Reader) []string {
br := bufio.NewReader(r)
var res []string
for {
s, _, err := br.ReadLine()
if err != nil {
return res
}
res = append(res, string(s))
}
}
func ListFiles(folder string) []string {
var res []string
filepath.Walk(fmt.Sprintf(folder),
func(path string, info os.FileInfo, err error) error {
if info != nil && !info.IsDir() {
res = append(res, info.Name())
}
return nil
})
return res
}
func FileExists(filename string) bool {
if _, err := os.Stat(filename); os.IsNotExist(err) {
return false
}
return true
}