-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.go
80 lines (65 loc) · 1.3 KB
/
content.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
70
71
72
73
74
75
76
77
78
79
80
package gcsfs
import (
"io/fs"
"path"
"strings"
"time"
"cloud.google.com/go/storage"
)
type content struct {
name string
isDir bool
size int64
modTime time.Time
}
var (
_ fs.DirEntry = (*content)(nil)
_ fs.FileInfo = (*content)(nil)
)
func newContent(attrs *storage.ObjectAttrs) *content {
if attrs.Name == "" {
return newDirContent(attrs.Prefix)
}
return newFileContent(attrs)
}
func newDirContent(prefix string) *content {
return &content{
name: path.Base(strings.TrimSuffix(prefix, "/")),
isDir: true,
}
}
func newFileContent(attrs *storage.ObjectAttrs) *content {
return &content{
name: path.Base(attrs.Name),
size: attrs.Size,
modTime: attrs.Updated,
}
}
func (c *content) Name() string {
return c.name
}
func (c *content) Size() int64 {
return c.size
}
// Mode returns if this content is directory then fs.ModePerm | fs.ModeDir otherwise fs.ModePerm.
func (c *content) Mode() fs.FileMode {
if c.isDir {
return fs.ModePerm | fs.ModeDir
}
return fs.ModePerm
}
func (c *content) ModTime() time.Time {
return c.modTime
}
func (c *content) IsDir() bool {
return c.isDir
}
func (c *content) Sys() interface{} {
return nil
}
func (c *content) Type() fs.FileMode {
return c.Mode() & fs.ModeType
}
func (c *content) Info() (fs.FileInfo, error) {
return c, nil
}