fs

package
v0.0.0-...-ebeccf4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 2 Imported by: 11

Documentation

Overview

Package fs provides types and methods for interacting with the filesystem, as an abstraction layer.

It provides an implementation that uses the operating system filesystem, and an interface that should be implemented if you want to provide your own filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Writer
	Name() string
	Fd() uintptr
	Stat() (os.FileInfo, error)
	WriteString(s string) (ret int, err error)
	Truncate(size int64) error
}

File represents a file in the filesystem.

type Fs

type Fs interface {
	// Create creates a file in the filesystem, returning the file and an
	// error, if any happens.
	Create(name string) (File, error)

	// Mkdir creates a directory in the filesystem, return an error if any
	// happens.
	Mkdir(name string, perm os.FileMode) error

	// MkdirAll creates a directory path and all parents that does not exist
	// yet.
	MkdirAll(path string, perm os.FileMode) 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.
	// It is the caller's responsibility to remove the directory when it is no longer needed.
	MkdirTemp(dir string, pattern string) (string, error)

	// Open opens a file, returning it or an error, if any happens.
	Open(name string) (File, error)

	// OpenFile opens a file using the given flags and the given mode.
	OpenFile(name string, flag int, perm os.FileMode) (File, error)

	// Remove removes a file identified by name, returning an error, if any
	// happens.
	Remove(name string) error

	// RemoveAll removes a directory path and all any children it contains. It
	// does not fail if the path does not exist (return nil).
	RemoveAll(path string) error

	// Rename renames a file.
	Rename(oldname, newname string) error

	// Stat returns a FileInfo describing the named file, or an error, if any
	// happens.
	Stat(name string) (os.FileInfo, error)
}

Fs is the filesystem interface.

Any simulated or real filesystem should implement this interface.

type OsFs

type OsFs struct{}

OsFs is a Fs implementation that uses functions provided by the os package.

For details in any method, check the documentation of the os package (http://golang.org/pkg/os/).

func (OsFs) Create

func (OsFs) Create(name string) (File, error)

func (OsFs) Mkdir

func (OsFs) Mkdir(name string, perm os.FileMode) error

func (OsFs) MkdirAll

func (OsFs) MkdirAll(path string, perm os.FileMode) error

func (OsFs) MkdirTemp

func (OsFs) MkdirTemp(dir string, pattern string) (string, error)

func (OsFs) Open

func (OsFs) Open(name string) (File, error)

func (OsFs) OpenFile

func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (OsFs) Remove

func (OsFs) Remove(name string) error

func (OsFs) RemoveAll

func (OsFs) RemoveAll(path string) error

func (OsFs) Rename

func (OsFs) Rename(oldname, newname string) error

func (OsFs) Stat

func (OsFs) Stat(name string) (os.FileInfo, error)

Directories

Path Synopsis
Package fstest provides fake implementations of the fs package.
Package fstest provides fake implementations of the fs package.

Jump to

Keyboard shortcuts

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