fs

package
v0.0.0-...-31c1c1e Latest Latest
Warning

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

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

Documentation

Overview

Package fs provides a simple interface for a filesystem

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskConfig

type DiskConfig struct {
	// Dir is the path to the directory to observe
	Dir string

	// Size of the filesystem in bytes
	Size int64

	// For logging, optional
	Logger log.Logger
}

DiskConfig is the config required to create a new disk filesystem.

type File

type File interface {
	io.ReadCloser

	// Name returns the Name of the file
	Name() string

	// Stat returns the FileInfo to this file. In case of an error
	// FileInfo is nil and the error is non-nil.
	Stat() (FileInfo, error)
}

File provides access to a single file.

type FileInfo

type FileInfo interface {
	// Name returns the full name of the file
	Name() string

	// Size reports the size of the file in bytes
	Size() int64

	// ModTime returns the time of last modification
	ModTime() time.Time

	// IsLink returns the path this file is linking to and true. Otherwise an empty string and false.
	IsLink() (string, bool)

	// IsDir returns whether the file represents a directory
	IsDir() bool
}

FileInfo describes a file and is returned by Stat.

type Filesystem

type Filesystem interface {
	// Base returns the base path of this filesystem
	Base() string

	// Rebase sets a new base path for this filesystem
	Rebase(string) error

	// Size returns the consumed size and capacity of the filesystem in bytes. The
	// capacity is negative if the filesystem can consume as much space as it can.
	Size() (int64, int64)

	// Resize resizes the filesystem to the new size. Files may need to be deleted.
	Resize(size int64)

	// Files returns the current number of files in the filesystem.
	Files() int64

	// Symlink creates newname as a symbolic link to oldname.
	Symlink(oldname, newname string) error

	// Open returns the file stored at the given path. It returns nil if the
	// file doesn't exist.
	Open(path string) File

	// Store adds a file to the filesystem. Returns the size of the data that has been
	// stored in bytes and whether the file is new. The size is negative if there was
	// an error adding the file and error is not nil.
	Store(path string, r io.Reader) (int64, bool, error)

	// Delete removes a file at the given path from the filesystem. Returns the size of
	// the remove file in bytes. The size is negative if the file doesn't exist.
	Delete(path string) int64

	// DeleteAll removes all files from the filesystem. Returns the size of the
	// removed files in bytes.
	DeleteAll() int64

	// List lists all files that are currently on the filesystem.
	List(pattern string) []FileInfo
}

Filesystem is an interface that provides access to a filesystem.

func NewDiskFilesystem

func NewDiskFilesystem(config DiskConfig) (Filesystem, error)

NewDiskFilesystem returns a new filesystem that is backed by a disk that implements the Filesystem interface

func NewDummyFilesystem

func NewDummyFilesystem() Filesystem

NewDummyFilesystem return a dummy filesystem

func NewMemFilesystem

func NewMemFilesystem(config MemConfig) Filesystem

NewMemFilesystem creates a new filesystem in memory that implements the Filesystem interface.

type MemConfig

type MemConfig struct {
	// Base is the base path to be reported for this filesystem
	Base string

	// Size is the capacity of the filesystem in bytes
	Size int64

	// Set true to automatically delete the oldest files until there's
	// enough space to store a new file
	Purge bool

	// For logging, optional
	Logger log.Logger
}

MemConfig is the config that is required for creating a new memory filesystem.

Jump to

Keyboard shortcuts

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