Source file
src/io/fs/format.go
1
2
3
4
5 package fs
6
7 import (
8 "time"
9 )
10
11
12
13
14
15
16
17 func FormatFileInfo(info FileInfo) string {
18 name := info.Name()
19 b := make([]byte, 0, 40+len(name))
20 b = append(b, info.Mode().String()...)
21 b = append(b, ' ')
22
23 size := info.Size()
24 var usize uint64
25 if size >= 0 {
26 usize = uint64(size)
27 } else {
28 b = append(b, '-')
29 usize = uint64(-size)
30 }
31 var buf [20]byte
32 i := len(buf) - 1
33 for usize >= 10 {
34 q := usize / 10
35 buf[i] = byte('0' + usize - q*10)
36 i--
37 usize = q
38 }
39 buf[i] = byte('0' + usize)
40 b = append(b, buf[i:]...)
41 b = append(b, ' ')
42
43 b = append(b, info.ModTime().Format(time.DateTime)...)
44 b = append(b, ' ')
45
46 b = append(b, name...)
47 if info.IsDir() {
48 b = append(b, '/')
49 }
50
51 return string(b)
52 }
53
54
55
56
57
58
59
60 func FormatDirEntry(dir DirEntry) string {
61 name := dir.Name()
62 b := make([]byte, 0, 5+len(name))
63
64
65
66 mode := dir.Type().String()
67 mode = mode[:len(mode)-9]
68
69 b = append(b, mode...)
70 b = append(b, ' ')
71 b = append(b, name...)
72 if dir.IsDir() {
73 b = append(b, '/')
74 }
75 return string(b)
76 }
77
View as plain text