-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
69 lines (56 loc) · 1.13 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
66
67
68
69
package cab
import (
"io"
"io/fs"
"path"
"time"
)
type File struct {
Name string
Modified time.Time
Attributes uint16
header cabinetFileEntryHeader
folder *cabinetFileFolder
}
const (
AttributeReadOnly = 0x1
AttributeHidden = 0x2
AttributeSystem = 0x4
AttributeArch = 0x20
AttributeExec = 0x40
AttributeNameUtf = 0x80
)
func (f *File) Open() (io.Reader, error) {
folderReader, err := f.folder.open()
if err != nil {
return nil, err
}
if _, err := io.CopyN(io.Discard, folderReader, int64(f.header.UncompressedOffsetInFolder)); err != nil {
return nil, err
}
return io.LimitReader(folderReader, int64(f.header.UncompressedFileSize)), nil
}
func (f *File) Stat() fs.FileInfo {
return FileInfo{f}
}
type FileInfo struct {
File *File
}
func (f FileInfo) Name() string {
return path.Base(f.File.Name)
}
func (f FileInfo) Size() int64 {
return int64(f.File.header.UncompressedFileSize)
}
func (f FileInfo) Mode() fs.FileMode {
return 0
}
func (f FileInfo) ModTime() time.Time {
return f.File.Modified
}
func (f FileInfo) IsDir() bool {
return false
}
func (f FileInfo) Sys() any {
return f.File
}