-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
61 lines (50 loc) · 1 KB
/
file.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
package snake
import (
"bytes"
"os"
)
type snakefile struct {
Input *os.File
}
// FileOperate ...
type FileOperate interface {
Get() *os.File
String() *SnakeString
Byte() []byte
Close() error // 关闭文件链接
}
// ---------------------------------------
// 输入 :
// File 初始化...
func File(f *os.File) FileOperate {
return &snakefile{Input: f}
}
// ---------------------------------------
// 输出 :
// Get 获取文本...
func (sk *snakefile) Get() *os.File {
return sk.Input
}
// Add 在字符串中追加文字...
func (sk *snakefile) Close() error {
return sk.Input.Close()
}
// Text 获取文本...
func (sk *snakefile) String() *SnakeString {
var buf bytes.Buffer
_, err := buf.ReadFrom(sk.Input)
if err != nil {
// todo: 字符串转化错误消息
return String()
}
return String(buf.String())
}
// Text 获取文本 []byte ...
func (sk *snakefile) Byte() []byte {
var buf bytes.Buffer
_, err := buf.ReadFrom(sk.Input)
if err != nil {
return nil
}
return buf.Bytes()
}