filesystem

package
v0.0.0-...-ad3f07b Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SharedAccess  = MMapAccess(mmap.MAP_SHARED)
	PrivateAccess = MMapAccess(mmap.MAP_PRIVATE)
)
View Source
const (
	ReadOnlyMode  = MMapMode(mmap.PROT_READ)
	WriteOnlyMode = MMapMode(mmap.PROT_WRITE)
	ReadWriteMode = MMapMode(mmap.PROT_READ | mmap.PROT_WRITE)
)

Variables

This section is empty.

Functions

func AbsolutePath

func AbsolutePath(root, path string) string

func GetBlockSize

func GetBlockSize(path string) (int, error)

func GetPageSize

func GetPageSize() int

func RelativePath

func RelativePath(root, path string) string

func ResolveVirtualPath

func ResolveVirtualPath(root, p string) string

Types

type DiskFilesystem

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

func (*DiskFilesystem) Copy

func (d *DiskFilesystem) Copy(source, destination string) error

func (*DiskFilesystem) CreateDir

func (d *DiskFilesystem) CreateDir(path string) error

func (*DiskFilesystem) Exists

func (d *DiskFilesystem) Exists(path string) bool

func (*DiskFilesystem) FileHash

func (d *DiskFilesystem) FileHash(path string, hasher hashing.Hasher) (hashing.Sum, error)

func (*DiskFilesystem) Open

func (d *DiskFilesystem) Open(name string, flags int, perm os.FileMode) (File, error)

func (*DiskFilesystem) ReadDir

func (d *DiskFilesystem) ReadDir(path string, recursive bool) ([]os.DirEntry, error)

func (*DiskFilesystem) ReadFile

func (d *DiskFilesystem) ReadFile(path string) ([]byte, error)

func (*DiskFilesystem) Remove

func (d *DiskFilesystem) Remove(path string) error

func (*DiskFilesystem) Rename

func (d *DiskFilesystem) Rename(oldPath, newPath string) error

func (DiskFilesystem) RootAbs

func (b DiskFilesystem) RootAbs() string

func (DiskFilesystem) RootDir

func (b DiskFilesystem) RootDir() string

func (*DiskFilesystem) Stat

func (d *DiskFilesystem) Stat(path string) (os.FileInfo, error)

func (*DiskFilesystem) Sub

func (d *DiskFilesystem) Sub(dir string) (FileSystem, error)

func (DiskFilesystem) Unwatch

func (b DiskFilesystem) Unwatch(path string, callback chan Event) error

func (DiskFilesystem) Watch

func (b DiskFilesystem) Watch(path string, callback chan Event) error

func (*DiskFilesystem) WriteFile

func (d *DiskFilesystem) WriteFile(path string, data []byte) error

type Event

type Event = fsnotify.Event

type File

type File interface {
	io.Reader
	io.ReaderAt
	io.Writer
	io.WriterAt
	io.Seeker
	io.Closer

	Slice(start int64, end int64) ([]byte, error)
	Truncate(size int64) error
	Stat() (os.FileInfo, error)
	Sync() error
}

File is the interface compatible with os.File.

type FileSystem

type FileSystem interface {
	// Open opens the named file.
	Open(name string, flags int, perm os.FileMode) (File, error)
	// ReadDir returns a slice of directory entries in the named directory.
	ReadDir(path string, recursive bool) ([]os.DirEntry, error)
	// ReadFile reads and returns the content of the named file.
	ReadFile(path string) ([]byte, error)
	// WriteFile writes the content to the named file.
	WriteFile(path string, data []byte) error
	// CreateDir creates a new directory with the given name.
	CreateDir(path string) error
	// Remove removes the named file or directory.
	Remove(path string) error
	// Rename renames the named file or directory to newPath.
	Rename(oldPath, newPath string) error
	// Copy copies source file to destination
	Copy(source, destination string) error
	// Stat returns the FileInfo for the named file or directory.
	Stat(path string) (os.FileInfo, error)
	// Exists checks if the named file or directory exists.
	Exists(path string) bool
	// FileHash hashes the content of the named file with the given hash function.
	FileHash(path string, hasher hashing.Hasher) (hashing.Sum, error)
	// Sub returns a new FileSystem rooted at dir
	Sub(dir string) (FileSystem, error)
	// Watch a file or directory for changes.
	Watch(path string, callback chan Event) error
	// Unwatch removes a watch on a file or directory.
	Unwatch(path string, callback chan Event) error
	// RootDir Returns the root directory of the filesystem.
	RootDir() string
	// RootAbs Returns the absolute path to the root directory of the filesystem.
	RootAbs() string
}

func NewDiskFilesystem

func NewDiskFilesystem() FileSystem

func NewMMapFilesystem

func NewMMapFilesystem(options *MMapOptions) FileSystem

func NewMemoryFilesystem

func NewMemoryFilesystem() FileSystem

type MMapAccess

type MMapAccess mmap.MapType

type MMapFilesystem

type MMapFilesystem struct {
	FileSystem
	// contains filtered or unexported fields
}

func (*MMapFilesystem) Open

func (m *MMapFilesystem) Open(name string, flags int, perm os.FileMode) (File, error)

type MMapMode

type MMapMode mmap.Prot

type MMapOptions

type MMapOptions struct {
	Access MMapAccess
	Mode   MMapMode
	Sync   SyncType
}

type MemoryFilesystem

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

func (*MemoryFilesystem) Copy

func (m *MemoryFilesystem) Copy(source, destination string) error

func (*MemoryFilesystem) CreateDir

func (m *MemoryFilesystem) CreateDir(dir string) error

func (*MemoryFilesystem) Exists

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

func (*MemoryFilesystem) FileHash

func (m *MemoryFilesystem) FileHash(path string, hasher hashing.Hasher) (hashing.Sum, error)

func (*MemoryFilesystem) Open

func (m *MemoryFilesystem) Open(name string, flags int, perm os.FileMode) (File, error)

func (*MemoryFilesystem) ReadDir

func (m *MemoryFilesystem) ReadDir(dir string, recursive bool) ([]os.DirEntry, error)

func (*MemoryFilesystem) ReadFile

func (m *MemoryFilesystem) ReadFile(path string) ([]byte, error)

func (*MemoryFilesystem) Remove

func (m *MemoryFilesystem) Remove(path string) error

func (*MemoryFilesystem) Rename

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

func (MemoryFilesystem) RootAbs

func (b MemoryFilesystem) RootAbs() string

func (MemoryFilesystem) RootDir

func (b MemoryFilesystem) RootDir() string

func (*MemoryFilesystem) Stat

func (m *MemoryFilesystem) Stat(path string) (os.FileInfo, error)

func (*MemoryFilesystem) Sub

func (m *MemoryFilesystem) Sub(dir string) (FileSystem, error)

func (*MemoryFilesystem) Unwatch

func (m *MemoryFilesystem) Unwatch(path string, callback chan Event) error

func (*MemoryFilesystem) Watch

func (m *MemoryFilesystem) Watch(path string, callback chan Event) error

func (*MemoryFilesystem) WriteFile

func (m *MemoryFilesystem) WriteFile(path string, data []byte) error

type SyncType

type SyncType int
const (
	// SyncNormal will sync all changes when the file is closed or a call to Sync() is made or
	// when the OS decides to flush the data to disk.
	SyncNormal SyncType = iota
	// SyncFull will call Sync() whenever a call to Write or WriteAt is made
	SyncFull
)

Jump to

Keyboard shortcuts

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