github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/vals/file.go (about) 1 package vals 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/u-root/u-root/cmds/core/elvish/hash" 8 "github.com/u-root/u-root/cmds/core/elvish/parse" 9 ) 10 11 // File wraps a pointer to os.File. 12 type File struct { 13 Inner *os.File 14 } 15 16 var _ interface{} = File{} 17 18 // NewFile creates a new File value. 19 func NewFile(inner *os.File) File { 20 return File{inner} 21 } 22 23 func (File) Kind() string { 24 return "file" 25 } 26 27 func (f File) Equal(rhs interface{}) bool { 28 return f == rhs 29 } 30 31 func (f File) Hash() uint32 { 32 return hash.Hash(f.Inner.Fd()) 33 } 34 35 func (f File) Repr(int) string { 36 return fmt.Sprintf("<file{%s %p}>", parse.Quote(f.Inner.Name()), f.Inner) 37 }