-
Notifications
You must be signed in to change notification settings - Fork 1
/
stat.go
62 lines (48 loc) · 1.3 KB
/
stat.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
package gofat
import (
"os"
"strings"
"time"
)
func (h *ExtendedEntryHeader) FileInfo() os.FileInfo {
return entryHeaderFileInfo{*h}
}
type entryHeaderFileInfo struct {
entry ExtendedEntryHeader
}
func (e entryHeaderFileInfo) Name() string {
if e.entry.ExtendedName != "" {
return e.entry.ExtendedName
}
name := strings.TrimRight(string(e.entry.Name[:8]), " ")
ext := strings.TrimRight(string(e.entry.Name[8:11]), " ")
if ext != "" {
name += "."
}
return name + ext
}
func (e entryHeaderFileInfo) Size() int64 {
return int64(e.entry.FileSize)
}
func (e entryHeaderFileInfo) Mode() os.FileMode {
if e.IsDir() {
return os.ModeDir
}
return 0
}
func (e entryHeaderFileInfo) ModTime() time.Time {
writeDate := ParseDate(e.entry.WriteDate)
writeTime := ParseTime(e.entry.WriteTime)
// If the date IsZero() it contained any invalid value in which case we return time.Time{}.
// For writeTime we cannot do that because writeTime.IsZero() is perfectly valid.
if writeDate.IsZero() {
return time.Time{}
}
return time.Date(writeDate.Year(), writeDate.Month(), writeDate.Day(), writeTime.Hour(), writeTime.Minute(), writeTime.Second(), 0, time.UTC)
}
func (e entryHeaderFileInfo) IsDir() bool {
return e.entry.Attribute&0x10 == 0x10
}
func (e entryHeaderFileInfo) Sys() interface{} {
return e.entry
}