file.go (1192B)
1 package lib9p 2 3 import ( 4 "io/fs" 5 ) 6 7 // A File is an open file. 8 // The interface is similar to that of [fs.File], but Stat returns 9 // [*FileInfo] of this package instead of [fs.FileInfo]. 10 type File interface { 11 Stat() (*FileInfo, error) 12 Read([]byte) (int, error) 13 Close() error 14 } 15 16 // A WriterFile is a file with Write method. 17 // If the server is to accept Twrite messages, files in this server 18 // must implement this interface. 19 type WriterFile interface { 20 File 21 Write([]byte) (int, error) 22 } 23 24 // A WriterStatFile is a file which can modify its attributes such as 25 // the permission and the group (Note that changing ownership of a file 26 // is prohibited by the protocol). 27 type WriterStatFile interface { 28 File 29 // WStat sets file Stat to stat. 30 // After successful call, the file's Stat() method should return 31 // the same Stat as stat. 32 // If there is an error, file's status must remain the same as before. 33 WStat(stat *Stat) error 34 } 35 36 // A ReadDirFile is a directory. 37 // Every directory file shoul implement this interface. 38 // Non-directory files can implement this. In this case, ReadDir should 39 // return an error. 40 type ReadDirFile interface { 41 File 42 ReadDir(n int) ([]fs.DirEntry, error) 43 }