fs

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileOperationNotPermitted = errors.New("fake file does not exist and therefore this operation is not permitted.")
	ErrFileDoesNotExist          = errors.New("fake file does not exist")
)
View Source
var DefaultFilesystem = OSFileSystem{}

DefaultFilesystem is the default implementation of the FileSystem interface. It uses OSFileSystem to make functions of the os package the default for users.

Functions

This section is empty.

Types

type FakeFile

type FakeFile struct {
	Name    string
	Mode    os.FileMode
	ModTime time.Time
	Buffer  *bytes.Reader
}

Fake represents are readable in memory version of os.File which can be used for testing.

func NewFakeFile

func NewFakeFile(name, content string) FakeFile

NewFakeFile creates a new FakeFile instances based on a file name and it's contents from strings. The content of the new instance will be stored in an internal bytes.Reader instance. The default file mode will be 0777 and the last modification time the moment when the function is called.

func (FakeFile) Close

func (f FakeFile) Close() error

Close wraps io.Closer's functionality and does no operation.

func (FakeFile) Read

func (f FakeFile) Read(p []byte) (n int, err error)

Read wraps io.Reader's functionality around the internal bytes.Reader instance.

func (FakeFile) ReadAt

func (f FakeFile) ReadAt(p []byte, off int64) (n int, err error)

ReadAt wraps io.ReaderAt's functionality around the internalt bytes.Reader instance.

func (FakeFile) Seek

func (f FakeFile) Seek(offset int64, whence int) (int64, error)

Seek wraps io.Seeker's functionality around the internalt bytes.Reader instance.

func (FakeFile) Stat

func (f FakeFile) Stat() (os.FileInfo, error)

Stat returns the FakeFileInfo structure describing the FakeFile instance.

type FakeFileInfo

type FakeFileInfo struct {
	File FakeFile
}

FakeFileInfo describes a wrapped FakeFile instance and is returned by FakeFile.Stat

func (FakeFileInfo) IsDir

func (fi FakeFileInfo) IsDir() bool

IsDir always return false since it only uses FakeFile instances.

func (FakeFileInfo) ModTime

func (fi FakeFileInfo) ModTime() time.Time

ModTime returns the modification time of the FakeFile instance.

func (FakeFileInfo) Mode

func (fi FakeFileInfo) Mode() os.FileMode

Mode returns file mode bits of the FakeFile instance.

func (FakeFileInfo) Name

func (fi FakeFileInfo) Name() string

Name returns the base name of the FakeFile instance.

func (FakeFileInfo) Size

func (fi FakeFileInfo) Size() int64

Size returns the length in bytes of the file's internal bytes.Reader instance.

func (FakeFileInfo) Sys

func (fi FakeFileInfo) Sys() interface{}

Sys always returns nil to stay conformant to the os.FileInfo interface.

type FakeFilesystem

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

FakeFilesystem in memory implementations for the functions of the FileSystem interface to offer an implementation that can be used during in tests.

func NewFakeFilesystemWithFiles

func NewFakeFilesystemWithFiles(fs []FakeFile) FakeFilesystem

NewFakeFilesystemWithFiles creates a new FakeFilesystem instance bundled with a list of FakeFile instances that can be passed.

func (FakeFilesystem) Open

func (ff FakeFilesystem) Open(name string) (File, error)

Open searches in the internal map of FakeFile instances and returns it for reading. If successful, methods on the returned file can be used for reading. If the FakeFile instance cannot be found in the internal map an error of type *PathError will be returned.

func (FakeFilesystem) Stat

func (ff FakeFilesystem) Stat(name string) (os.FileInfo, error)

Stat returns the FakeFileInfo structure describing a FakeFile instance Found in the internal FakeFile map. If the FakeFile instance cannot be found in the internal map an error of type *PathError will be returned.

type File

type File interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	Stat() (os.FileInfo, error)
}

File is an interface that groups several read interfaces of the io package together with the Stat function of the os package to make reading astractions of the filesystem possible.

type FileSystem

type FileSystem interface {
	Open(name string) (File, error)
	Stat(name string) (os.FileInfo, error)
}

FileSystem is an interface that groups the common functions Open and Stat of the os package.

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem wraps the functions of the FileSystem interface around functions of the os package to offer an abstraction for the golang library.

func (OSFileSystem) Open

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

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *os.PathError.

func (OSFileSystem) Stat

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

Stat returns the os.FileInfo structure describing file. If there is an error, it will be of type *os.PathError.

Jump to

Keyboard shortcuts

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