gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

simplefileinfo.go (1545B)


      1 package rifs
      2 
      3 import (
      4 	"os"
      5 	"time"
      6 )
      7 
      8 // SimpleFileInfo is a simple `os.FileInfo` implementation useful for testing
      9 // with the bare minimum.
     10 type SimpleFileInfo struct {
     11 	filename string
     12 	isDir    bool
     13 	size     int64
     14 	mode     os.FileMode
     15 	modTime  time.Time
     16 }
     17 
     18 // NewSimpleFileInfoWithFile returns a new file-specific SimpleFileInfo.
     19 func NewSimpleFileInfoWithFile(filename string, size int64, mode os.FileMode, modTime time.Time) *SimpleFileInfo {
     20 	return &SimpleFileInfo{
     21 		filename: filename,
     22 		isDir:    false,
     23 		size:     size,
     24 		mode:     mode,
     25 		modTime:  modTime,
     26 	}
     27 }
     28 
     29 // NewSimpleFileInfoWithDirectory returns a new directory-specific
     30 // SimpleFileInfo.
     31 func NewSimpleFileInfoWithDirectory(filename string, modTime time.Time) *SimpleFileInfo {
     32 	return &SimpleFileInfo{
     33 		filename: filename,
     34 		isDir:    true,
     35 		mode:     os.ModeDir,
     36 		modTime:  modTime,
     37 	}
     38 }
     39 
     40 // Name returns the base name of the file.
     41 func (sfi *SimpleFileInfo) Name() string {
     42 	return sfi.filename
     43 }
     44 
     45 // Size returns the length in bytes for regular files; system-dependent for
     46 // others.
     47 func (sfi *SimpleFileInfo) Size() int64 {
     48 	return sfi.size
     49 }
     50 
     51 // Mode returns the file mode bits.
     52 func (sfi *SimpleFileInfo) Mode() os.FileMode {
     53 	return sfi.mode
     54 }
     55 
     56 // ModTime returns the modification time.
     57 func (sfi *SimpleFileInfo) ModTime() time.Time {
     58 	return sfi.modTime
     59 }
     60 
     61 // IsDir returns true if a directory.
     62 func (sfi *SimpleFileInfo) IsDir() bool {
     63 	return sfi.isDir
     64 }
     65 
     66 // Sys returns internal state.
     67 func (sfi *SimpleFileInfo) Sys() interface{} {
     68 	return nil
     69 }