fs

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForFileData

func CheckForFileData(fs FileSystem, url, mount string) (data []byte, mime, path string, ok bool)

func EnumerateCheckPaths

func EnumerateCheckPaths(src string) (checkPaths []string)

func FileExists

func FileExists(path string) (exists bool)

func FindFileMime

func FindFileMime(path string) (mime string, err error)

func FindFileShasum

func FindFileShasum(path string) (shasum string, err error)

func ListAllDirs

func ListAllDirs(path string) (dirs []string, err error)

func ListAllFiles

func ListAllFiles(path string) (files []string)

func ListDirs

func ListDirs(path string) (dirs []string, err error)

func ListFiles

func ListFiles(path string) (files []string)

func LookupFilePath added in v0.2.0

func LookupFilePath(fs FileSystem, basePath string, extensions ...string) (path string, present bool)

func PruneRootFrom added in v0.2.0

func PruneRootFrom[T string | []string](root string, path T) (pruned T)

func PruneRootFromSlice added in v0.2.1

func PruneRootFromSlice(root string, slice []string) (pruned []string)

func PruneRootFromString added in v0.2.1

func PruneRootFromString(root string, path string) (pruned string)

func PruneRootPrefixes added in v0.2.0

func PruneRootPrefixes(path string) (pruned string)

Types

type File

type File struct {
	Path string
	Name string
	Extn string
	Mime string
	Data []byte
}

func New

func New(path string) (file *File, err error)

func (File) String

func (f File) String() string

type FileSystem

type FileSystem interface {
	// ID is the filesystem identifier (kebab-cased feature tag)
	ID() (id string)
	// CloneROFS clones the existing filesystem as a new Read-Only instance
	CloneROFS() (cloned FileSystem)
	// Name is the underlying root path of the filesystem (not the mount-point)
	Name() (name string)
	Open(path string) (fh fs.File, err error)
	ListDirs(path string) (paths []string, err error)
	ListFiles(path string) (paths []string, err error)
	ListAllDirs(path string) (paths []string, err error)
	ListAllFiles(path string) (paths []string, err error)
	ReadDir(path string) (paths []fs.DirEntry, err error)
	ReadFile(path string) (content []byte, err error)
	MimeType(path string) (mime string, err error)
	// Shasum returns the 10-character, lower-cased hex encoded shasum of the file
	Shasum(path string) (shasum string, err error)
	// Sha256 returns the complete sha256 (hexadecimal encoded) hash of the file
	Sha256(path string) (shasum string, err error)
	FileCreated(path string) (created int64, err error)
	LastModified(path string) (dateTime int64, err error)
	Exists(path string) (exists bool)
	FileStats(path string) (mime, shasum string, created, updated time.Time, err error)
	FindFilePath(path string, extensions ...string) (realpath string, err error)
	ReadPageMatter(path string) (pm *matter.PageMatter, err error)
}

func GetFileSystem added in v0.2.11

func GetFileSystem(id string) (f FileSystem, ok bool)

func Wrap

func Wrap(path string, fs FileSystem) (out FileSystem, err error)

type FileSystems added in v0.4.0

type FileSystems []FileSystem

type GormFileSystem added in v0.2.2

type GormFileSystem interface {
	GormTx() (tx *gorm.DB)
	FindPathsWhere(path string, expressions ...clause.Expression) (found []string, err error)
}

type QueryFileSystem added in v0.2.0

type QueryFileSystem interface {
	FindPathsWithContextKey(path, key string) (found []string, err error)
	FindPathsWhereContextKeyEquals(path, key string, value interface{}) (found []string, err error)
	FindPathsWhereContextEquals(path string, conditions map[string]interface{}) (found []string, err error)
	FindPathsWhereContext(path string, orJsonConditions ...map[string]interface{}) (found []string, err error)
}

type RWFileSystem added in v0.1.0

type RWFileSystem interface {
	FileSystem

	CloneRWFS() (cloned RWFileSystem)
	BeginTransaction()
	RollbackTransaction()
	CommitTransaction()
	EndTransaction()

	MakeDir(path string, perm os.FileMode) (err error)
	MakeDirAll(path string, perm os.FileMode) (err error)

	Remove(path string) (err error)
	RemoveAll(path string) (err error)

	WriteFile(path string, data []byte, perm os.FileMode) (err error)
	ChangeTimes(path string, created, updated time.Time) (err error)

	WritePageMatter(pm *matter.PageMatter) (err error)
	RemovePageMatter(path string) (err error)
}

func WrapRW added in v0.1.0

func WrapRW(path string, fs RWFileSystem) (out RWFileSystem, err error)

type Registry added in v0.4.0

type Registry interface {
	// ID returns the identifier used when constructing the registry
	ID() (id string)

	// Register adds the given filesystems to the specified mount point
	Register(mount string, f ...FileSystem)

	// GetFileSystem returns the first FileSystem with the given identifier (not the same as ID)
	GetFileSystem(id string) (f FileSystem, ok bool)

	Lookup() (rl RegistryLookup)
}

func NewRegistry added in v0.4.0

func NewRegistry(id string) (r Registry)

type RegistryLookup added in v0.4.0

type RegistryLookup interface {
	// FileExists returns true if any of the known filesystems have a file matching the given path
	FileExists(path string) (exists bool)

	// ReadFile returns the file data
	ReadFile(path string) (data []byte, err error)

	// FindFileShasum returns the 10-character, hex encoded, shasum of the given path
	FindFileShasum(path string) (shasum string, err error)

	// FindFileSha256 returns the given path's sha256 byte hash, base64 encoded
	FindFileSha256(path string) (shasum string, err error)

	// FindFileMime returns the mime type of the given path
	FindFileMime(path string) (mime string, err error)

	// ListFiles returns the list of files in the specified directory path
	ListFiles(path string) (files []string)

	// ListAllFiles returns the recursive list of all files at the specified directory path
	ListAllFiles(path string) (files []string)

	// ListDirs returns the list of directories in the specified directory path
	ListDirs(path string) (dirs []string)

	// ListAllDirs returns the recursive list of all files at the specified directory path
	ListAllDirs(path string) (dirs []string)
}

type WrapFileSystem

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

func (WrapFileSystem) CloneROFS added in v0.2.5

func (w WrapFileSystem) CloneROFS() (cloned FileSystem)

func (WrapFileSystem) Exists

func (w WrapFileSystem) Exists(path string) (exists bool)

func (WrapFileSystem) FileCreated

func (w WrapFileSystem) FileCreated(path string) (created int64, err error)

func (WrapFileSystem) FileStats added in v0.1.0

func (w WrapFileSystem) FileStats(path string) (mime, shasum string, created, updated time.Time, err error)

func (WrapFileSystem) FindFilePath added in v0.2.0

func (w WrapFileSystem) FindFilePath(prefix string, extensions ...string) (path string, err error)

func (WrapFileSystem) ID added in v0.2.11

func (w WrapFileSystem) ID() (id string)

func (WrapFileSystem) LastModified

func (w WrapFileSystem) LastModified(path string) (updated int64, err error)

func (WrapFileSystem) ListAllDirs

func (w WrapFileSystem) ListAllDirs(path string) (paths []string, err error)

func (WrapFileSystem) ListAllFiles

func (w WrapFileSystem) ListAllFiles(path string) (paths []string, err error)

func (WrapFileSystem) ListDirs

func (w WrapFileSystem) ListDirs(path string) (paths []string, err error)

func (WrapFileSystem) ListFiles

func (w WrapFileSystem) ListFiles(path string) (paths []string, err error)

func (WrapFileSystem) MimeType

func (w WrapFileSystem) MimeType(path string) (mime string, err error)

func (WrapFileSystem) Name

func (w WrapFileSystem) Name() (name string)

func (WrapFileSystem) Open

func (w WrapFileSystem) Open(path string) (file fs.File, err error)

func (WrapFileSystem) ReadDir

func (w WrapFileSystem) ReadDir(path string) (entries []fs.DirEntry, err error)

func (WrapFileSystem) ReadFile

func (w WrapFileSystem) ReadFile(path string) (data []byte, err error)

func (WrapFileSystem) ReadPageMatter added in v0.2.0

func (w WrapFileSystem) ReadPageMatter(path string) (pm *matter.PageMatter, err error)

func (WrapFileSystem) Sha256 added in v0.5.1

func (w WrapFileSystem) Sha256(path string) (shasum string, err error)

func (WrapFileSystem) Shasum

func (w WrapFileSystem) Shasum(path string) (shasum string, err error)

type WrapRWFileSystem added in v0.1.0

type WrapRWFileSystem struct {
	WrapFileSystem
	// contains filtered or unexported fields
}

func (WrapRWFileSystem) BeginTransaction added in v0.2.5

func (w WrapRWFileSystem) BeginTransaction()

func (WrapRWFileSystem) ChangeTimes added in v0.5.0

func (w WrapRWFileSystem) ChangeTimes(path string, created, updated time.Time) (err error)

func (WrapRWFileSystem) CloneRWFS added in v0.2.5

func (w WrapRWFileSystem) CloneRWFS() (cloned RWFileSystem)

func (WrapRWFileSystem) CommitTransaction added in v0.2.5

func (w WrapRWFileSystem) CommitTransaction()

func (WrapRWFileSystem) EndTransaction added in v0.2.5

func (w WrapRWFileSystem) EndTransaction()

func (WrapRWFileSystem) ID added in v0.2.11

func (w WrapRWFileSystem) ID() (id string)

func (WrapRWFileSystem) MakeDir added in v0.1.0

func (w WrapRWFileSystem) MakeDir(path string, perm os.FileMode) (err error)

func (WrapRWFileSystem) MakeDirAll added in v0.1.0

func (w WrapRWFileSystem) MakeDirAll(path string, perm os.FileMode) (err error)

func (WrapRWFileSystem) Remove added in v0.1.0

func (w WrapRWFileSystem) Remove(path string) (err error)

func (WrapRWFileSystem) RemoveAll added in v0.1.0

func (w WrapRWFileSystem) RemoveAll(path string) (err error)

func (WrapRWFileSystem) RemovePageMatter added in v0.2.0

func (w WrapRWFileSystem) RemovePageMatter(path string) (err error)

func (WrapRWFileSystem) RollbackTransaction added in v0.2.5

func (w WrapRWFileSystem) RollbackTransaction()

func (WrapRWFileSystem) WriteFile added in v0.1.0

func (w WrapRWFileSystem) WriteFile(path string, data []byte, perm os.FileMode) (err error)

func (WrapRWFileSystem) WritePageMatter added in v0.2.0

func (w WrapRWFileSystem) WritePageMatter(pm *matter.PageMatter) (err error)

Jump to

Keyboard shortcuts

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