io

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: EUPL-1.2 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src Medium, srcPath string, dst Medium, dstPath string) error

Copy copies a file from one medium to another.

func EnsureDir

func EnsureDir(m Medium, path string) error

EnsureDir makes sure a directory exists in the given medium.

func IsFile

func IsFile(m Medium, path string) bool

IsFile checks if a path exists and is a regular file in the given medium.

func Read

func Read(m Medium, path string) (string, error)

Read retrieves the content of a file from the given medium.

func Write

func Write(m Medium, path, content string) error

Write saves the given content to a file in the given medium.

Types

type DirEntry

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

DirEntry provides a simple implementation of fs.DirEntry for mock testing.

func (DirEntry) Info

func (de DirEntry) Info() (fs.FileInfo, error)

func (DirEntry) IsDir

func (de DirEntry) IsDir() bool

func (DirEntry) Name

func (de DirEntry) Name() string

func (DirEntry) Type

func (de DirEntry) Type() fs.FileMode

type FileInfo

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

FileInfo provides a simple implementation of fs.FileInfo for mock testing.

func (FileInfo) IsDir

func (fi FileInfo) IsDir() bool

func (FileInfo) ModTime

func (fi FileInfo) ModTime() time.Time

func (FileInfo) Mode

func (fi FileInfo) Mode() fs.FileMode

func (FileInfo) Name

func (fi FileInfo) Name() string

func (FileInfo) Size

func (fi FileInfo) Size() int64

func (FileInfo) Sys

func (fi FileInfo) Sys() any

type Medium

type Medium interface {
	// Read retrieves the content of a file as a string.
	Read(path string) (string, error)

	// Write saves the given content to a file, overwriting it if it exists.
	Write(path, content string) error

	// EnsureDir makes sure a directory exists, creating it if necessary.
	EnsureDir(path string) error

	// IsFile checks if a path exists and is a regular file.
	IsFile(path string) bool

	// FileGet is a convenience function that reads a file from the medium.
	FileGet(path string) (string, error)

	// FileSet is a convenience function that writes a file to the medium.
	FileSet(path, content string) error

	// Delete removes a file or empty directory.
	Delete(path string) error

	// DeleteAll removes a file or directory and all its contents recursively.
	DeleteAll(path string) error

	// Rename moves a file or directory from oldPath to newPath.
	Rename(oldPath, newPath string) error

	// List returns the directory entries for the given path.
	List(path string) ([]fs.DirEntry, error)

	// Stat returns file information for the given path.
	Stat(path string) (fs.FileInfo, error)

	// Exists checks if a path exists (file or directory).
	Exists(path string) bool

	// IsDir checks if a path exists and is a directory.
	IsDir(path string) bool
}

Medium defines the standard interface for a storage backend. This allows for different implementations (e.g., local disk, S3, SFTP) to be used interchangeably.

var Local Medium

Local is a pre-initialized medium for the local filesystem. It uses "/" as root, providing unsandboxed access to the filesystem. For sandboxed access, use NewSandboxed with a specific root path.

func NewSandboxed

func NewSandboxed(root string) (Medium, error)

NewSandboxed creates a new Medium sandboxed to the given root directory. All file operations are restricted to paths within the root. The root directory will be created if it doesn't exist.

type MockMedium

type MockMedium struct {
	Files map[string]string
	Dirs  map[string]bool
}

MockMedium is an in-memory implementation of Medium for testing.

func NewMockMedium

func NewMockMedium() *MockMedium

NewMockMedium creates a new MockMedium instance.

func (*MockMedium) Delete

func (m *MockMedium) Delete(path string) error

Delete removes a file or empty directory from the mock filesystem.

func (*MockMedium) DeleteAll

func (m *MockMedium) DeleteAll(path string) error

DeleteAll removes a file or directory and all contents from the mock filesystem.

func (*MockMedium) EnsureDir

func (m *MockMedium) EnsureDir(path string) error

EnsureDir records that a directory exists in the mock filesystem.

func (*MockMedium) Exists

func (m *MockMedium) Exists(path string) bool

Exists checks if a path exists in the mock filesystem.

func (*MockMedium) FileGet

func (m *MockMedium) FileGet(path string) (string, error)

FileGet is a convenience function that reads a file from the mock filesystem.

func (*MockMedium) FileSet

func (m *MockMedium) FileSet(path, content string) error

FileSet is a convenience function that writes a file to the mock filesystem.

func (*MockMedium) IsDir

func (m *MockMedium) IsDir(path string) bool

IsDir checks if a path is a directory in the mock filesystem.

func (*MockMedium) IsFile

func (m *MockMedium) IsFile(path string) bool

IsFile checks if a path exists as a file in the mock filesystem.

func (*MockMedium) List

func (m *MockMedium) List(path string) ([]fs.DirEntry, error)

List returns directory entries for the mock filesystem.

func (*MockMedium) Read

func (m *MockMedium) Read(path string) (string, error)

Read retrieves the content of a file from the mock filesystem.

func (*MockMedium) Rename

func (m *MockMedium) Rename(oldPath, newPath string) error

Rename moves a file or directory in the mock filesystem.

func (*MockMedium) Stat

func (m *MockMedium) Stat(path string) (fs.FileInfo, error)

Stat returns file information for the mock filesystem.

func (*MockMedium) Write

func (m *MockMedium) Write(path, content string) error

Write saves the given content to a file in the mock filesystem.

Directories

Path Synopsis
Package local provides a local filesystem implementation of the io.Medium interface.
Package local provides a local filesystem implementation of the io.Medium interface.

Jump to

Keyboard shortcuts

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