Help us shape the future of Go! Take the 2026 Go Developer Survey

system

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 15 Imported by: 2

README

System I/O

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File the file

func New

func New(root ...string) *File

New create a new file struct

func (*File) Allow

func (f *File) Allow(patterns ...string) *File

Allow allow rel path

func (*File) AllowAbs

func (f *File) AllowAbs(patterns ...string) *File

AllowAbs allow abs path

func (*File) Append added in v1.0.0

func (f *File) Append(file string, reader io.Reader, perm uint32) (int, error)

Append Append writes data to the named file, creating it if necessary.

func (*File) AppendFile added in v1.0.0

func (f *File) AppendFile(file string, data []byte, perm uint32) (int, error)

AppendFile Append writes data to the named file, creating it if necessary. If the file does not exist, AppendFile creates it with permissions perm (before umask); otherwise AppendFile truncates it before writing, without changing permissions.

func (*File) Chmod

func (f *File) Chmod(name string, mode uint32) error

Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError. A different subset of the mode bits are used, depending on the operating system. On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used. On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file. On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used.

func (*File) CleanCache added in v1.0.0

func (f *File) CleanCache()

CleanCache clean the cache

func (*File) Copy

func (f *File) Copy(src string, dest string) error

Copy copy from src to dst

func (*File) Deny

func (f *File) Deny(patterns ...string) *File

Deny deny rel path

func (*File) DenyAbs

func (f *File) DenyAbs(patterns ...string) *File

DenyAbs deny abs path

func (*File) Exists

func (f *File) Exists(name string) (bool, error)

Exists returns a boolean indicating whether the error is known to report that a file or directory already exists. It is satisfied by ErrExist as well as some syscall errors.

func (*File) Glob added in v1.0.0

func (f *File) Glob(pattern string) ([]string, error)

Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').

func (*File) Insert added in v1.0.0

func (f *File) Insert(file string, offset int64, reader io.Reader, perm uint32) (int, error)

Insert Insert writes data to the named file at the specified offset, creating it if necessary. @todo

  • it should be improved to support large files and avoid reading the entire file into memory.

func (*File) InsertFile added in v1.0.0

func (f *File) InsertFile(file string, offset int64, data []byte, perm uint32) (int, error)

InsertFile Insert writes data to the named file at the specified offset, creating it if necessary. If the file does not exist, InsertFile creates it with permissions perm (before umask); otherwise AppendFile truncates it before writing, without changing permissions. @todo

  • It should be improved to support large files and avoid reading the entire file into memory.

func (*File) IsDir

func (f *File) IsDir(name string) bool

IsDir check the given path is dir

func (*File) IsFile

func (f *File) IsFile(name string) bool

IsFile check the given path is file

func (f *File) IsLink(name string) bool

IsLink check the given path is symbolic link

func (*File) List added in v1.0.0

func (f *File) List(path string, types []string, page, pageSize int, filter func(string) bool) ([]string, int, int, error)

List list the files

func (*File) MimeType

func (f *File) MimeType(name string) (string, error)

MimeType return the MimeType

func (*File) Mkdir

func (f *File) Mkdir(dir string, perm uint32) error

Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type *PathError.

func (*File) MkdirAll

func (f *File) MkdirAll(dir string, perm uint32) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

func (*File) MkdirTemp

func (f *File) MkdirTemp(dir string, pattern string) (string, error)

MkdirTemp creates a new temporary directory in the directory dir and returns the pathname of the new directory. The new directory's name is generated by adding a random string to the end of pattern. If pattern includes a "*", the random string replaces the last "*" instead. If dir is the empty string, MkdirTemp uses the default directory for temporary files, as returned by TempDir. Multiple programs or goroutines calling MkdirTemp simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when it is no longer needed.

func (*File) ModTime

func (f *File) ModTime(name string) (time.Time, error)

ModTime return the file modification time

func (*File) Mode

func (f *File) Mode(name string) (uint32, error)

Mode return the file mode bits

func (*File) Move

func (f *File) Move(oldpath string, newpath string) error

Move move from oldpath to newpath

func (*File) ReadCloser added in v1.0.0

func (f *File) ReadCloser(file string) (io.ReadCloser, error)

ReadCloser returns a ReadCloser with the file content

func (*File) ReadDir

func (f *File) ReadDir(dir string, recursive bool) ([]string, error)

ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error.

func (*File) ReadFile

func (f *File) ReadFile(file string) ([]byte, error)

ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

func (*File) ReadOnly added in v1.0.0

func (f *File) ReadOnly() *File

ReadOnly set the read only flag

func (*File) Remove

func (f *File) Remove(name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func (*File) RemoveAll

func (f *File) RemoveAll(name string) error

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *PathError.

func (*File) Resize added in v1.0.0

func (f *File) Resize(inputPath, outputPath string, width, height uint) error

Resize resize the image

func (*File) Root added in v1.0.0

func (f *File) Root() string

Root get the root path

func (*File) Size

func (f *File) Size(name string) (int, error)

Size return the length in bytes for regular files; system-dependent for others

func (*File) Walk added in v1.0.0

func (f *File) Walk(root string, handler func(root, file string, isdir bool) error, patterns ...string) error

Walk traverse folders and read file contents

func (*File) Write added in v1.0.0

func (f *File) Write(file string, reader io.Reader, perm uint32) (int, error)

Write writes data to the named file, creating it if necessary.

func (*File) WriteCloser added in v1.0.0

func (f *File) WriteCloser(file string, perm uint32) (io.WriteCloser, error)

WriteCloser returns a WriteCloser with the file content

func (*File) WriteFile

func (f *File) WriteFile(file string, data []byte, perm uint32) (int, error)

WriteFile writes data to the named file, creating it if necessary.

If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions.

type Mode added in v1.0.0

type Mode uint8

Mode the mode of the file system

const (
	// ReadOnly the read only mode
	ReadOnly Mode = 1
	// ReadWrite the read write mode
	ReadWrite Mode = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL