-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
65 lines (54 loc) · 1.03 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
62
63
64
65
package main
import (
"hash"
"io/fs"
"os"
)
// FileInfo extends os.FileInfo with a HashFunc and Hash value
type FileInfo interface {
os.FileInfo
FullPath() string
Hash() []byte
HashFunc() hash.Hash
}
// File represents an OS file
type File struct {
os.FileInfo
fullPath string
hash []byte
hashFunc hash.Hash
}
// FullPath returns the file path + file name
func (f *File) FullPath() string {
return f.fullPath
}
// SetFullPath sets FullPath
func (f *File) SetFullPath(val string) {
f.fullPath = val
}
// Hash returns the hash value
func (f *File) Hash() []byte {
return f.hash
}
// SetHash sets hash
func (f *File) SetHash(val []byte) {
f.hash = val
}
// HashFunc returns the Hashing function used
func (f *File) HashFunc() hash.Hash {
return f.hashFunc
}
// SetHashFunc sets hashFunc
func (f *File) SetHashFunc(val hash.Hash) {
f.hashFunc = val
}
// NewFile returns a File
func NewFile(de fs.DirEntry) (*File, error) {
info, err := de.Info()
if err != nil {
return nil, err
}
return &File{
FileInfo: info,
}, nil
}