Skip to content

Instantly share code, notes, and snippets.

@JohnStarich
Created February 16, 2022 06:01
Show Gist options
  • Save JohnStarich/a85fa24dd080fec283b8f0aa4ce4cb9c to your computer and use it in GitHub Desktop.
Save JohnStarich/a85fa24dd080fec283b8f0aa4ce4cb9c to your computer and use it in GitHub Desktop.
HackpadFS article – HackpadFS extension interfaces
// Equivalent interfaces to io/fs
type FS = fs.FS
type FileInfo = fs.FileInfo
type DirEntry = fs.DirEntry
type File = fs.File
// New FS interfaces:
type SubFS interface { FS; Sub(dir string) (FS, error) }
type OpenFileFS interface { FS; OpenFile(name string, flag int, perm FileMode) (File, error) }
type CreateFS interface { FS; Create(name string) (File, error) }
type MkdirFS interface { FS; Mkdir(name string, perm FileMode) error }
type MkdirAllFS interface { FS; MkdirAll(path string, perm FileMode) error }
type RemoveFS interface { FS; Remove(name string) error }
type RemoveAllFS interface { FS; RemoveAll(name string) error }
type RenameFS interface { FS; Rename(oldname, newname string) error }
type StatFS interface { FS; Stat(name string) (FileInfo, error) }
type LstatFS interface { FS; Lstat(name string) (FileInfo, error) }
type ChmodFS interface { FS; Chmod(name string, mode FileMode) error }
type ChownFS interface { FS; Chown(name string, uid, gid int) error }
type ChtimesFS interface { FS; Chtimes(name string, atime time.Time, mtime time.Time) error }
type ReadDirFS interface { FS; ReadDir(name string) ([]DirEntry, error) }
type ReadFileFS interface { FS; ReadFile(name string) ([]byte, error) }
type SymlinkFS interface { FS; Symlink(oldname, newname string) error }
type MountFS interface { FS; Mount(name string) (mountFS FS, subPath string) }
// New File interfaces:
type ReadWriterFile interface { File; io.Writer }
type ReaderAtFile interface { File; io.ReaderAt }
type WriterAtFile interface { File; io.WriterAt }
type DirReaderFile interface { File; ReadDir(n int) ([]DirEntry, error) }
type SeekerFile interface { File; io.Seeker }
type SyncerFile interface { File; Sync() error }
type TruncaterFile interface { File; Truncate(size int64) error }
type ChmoderFile interface { File; Chmod(mode FileMode) error }
type ChownerFile interface { File; Chown(uid, gid int) error }
type ChtimeserFile interface { File; Chtimes(atime time.Time, mtime time.Time) error }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment