Skip to content

Instantly share code, notes, and snippets.

@JohnStarich
Created February 16, 2022 06:09
Show Gist options
  • Save JohnStarich/714e8e8b25e8873d802f1b3de269aaa8 to your computer and use it in GitHub Desktop.
Save JohnStarich/714e8e8b25e8873d802f1b3de269aaa8 to your computer and use it in GitHub Desktop.
HackpadFS article – HackpadFS helpers
// Equivalent helpers to io/fs
func ReadDir(fs FS, name string) ([]DirEntry, error)
func ReadFile(fs FS, name string) ([]byte, error)
func Stat(fs FS, name string) (FileInfo, error)
func Sub(fs FS, dir string) (FS, error)
func WalkDir(fs FS, root string, fn WalkDirFunc) error
// New FS helpers
func Chmod(fs FS, name string, mode FileMode) error
func Chown(fs FS, name string, uid, gid int) error
func Chtimes(fs FS, name string, atime time.Time, mtime time.Time) error
func Create(fs FS, name string) (File, error)
func Lstat(fs FS, name string) (FileInfo, error)
func LstatOrStat(fs FS, name string) (FileInfo, error)
func Mkdir(fs FS, name string, perm FileMode) error
func MkdirAll(fs FS, path string, perm FileMode) error
func OpenFile(fs FS, name string, flag int, perm FileMode) (File, error)
func Remove(fs FS, name string) error
func RemoveAll(fs FS, path string) error
func Rename(fs FS, oldName, newName string) error
func Symlink(fs FS, oldname, newname string) error
// New File helpers
func ChmodFile(file File, mode FileMode) error
func ChownFile(file File, uid, gid int) error
func ChtimesFile(file File, atime, mtime time.Time) error
func ReadAtFile(file File, p []byte, off int64) (n int, err error)
func WriteFile(file File, p []byte) (n int, err error)
func WriteAtFile(file File, p []byte, off int64) (n int, err error)
func ReadDirFile(file File, n int) ([]DirEntry, error)
func SeekFile(file File, offset int64, whence int) (int64, error)
func SyncFile(file File) error
func TruncateFile(file File, size int64) error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment