file

package
v0.0.0-...-82bc1ab Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDirectoryCollision occurs when merging directories with the name subdir names
	ErrDirectoryCollision = errors.New("tried to merge directories with identically named subdirs")
	// ErrFileCollision occurs when merging directories with the name file names
	ErrFileCollision = errors.New("tried to merge firectories with identically named files")
)
View Source
var (
	// ErrAlreadyClosed is returned when a file is closed twice
	ErrAlreadyClosed = errors.New("file was already closed")
	// ErrFileOpen is returned when a file is opened twice
	ErrFileOpen = errors.New("file is already opened")
	// ErrNotOpen is returned when a file is accessed while closed
	ErrNotOpen = errors.New("fie has not been opened")
)
View Source
var ErrMissingDir = errors.New("subdir not found")

ErrMissingDir occurs when requesting a subtree for a non-existent directory

Functions

This section is empty.

Types

type Dir

type Dir struct {
	Path  string
	Dirs  map[string]*Dir
	Files map[string]*File
}

Dir represents a generic directory on Disk

func NewDir

func NewDir(path string) (d *Dir, err error)

NewDir creates a Dir from the specified path, recursively

func (*Dir) Merge

func (d *Dir) Merge(other *Dir) (next *Dir, err error)

Merge combines two directories as if they shared the same root

func (*Dir) Mkdir

func (d *Dir) Mkdir(name string) (dir *Dir, err error)

Mkdir creates a new directory immediately inside of this directory

func (*Dir) Read

func (d *Dir) Read() (err error)

Read updates the contents of this directory from disk

func (*Dir) RemoveAll

func (d *Dir) RemoveAll(name string) error

RemoveAll recursively removes a subdirectory from disk

type File

type File struct {
	Name     string
	Ext      string
	Dir      string
	Mode     fs.FileMode
	Modified time.Time
	// contains filtered or unexported fields
}

File is a generic representation of a File on disk

func NewFile

func NewFile(dir, name string) (f *File)

NewFile creates a new File from the specified path

func (*File) Close

func (f *File) Close() (err error)

Close the file if it is open

func (*File) Create

func (f *File) Create(mode os.FileMode) (err error)

Create opens the file, encuring it is creaded on disk if missing

func (*File) Duplicate

func (f *File) Duplicate(src *File) error

Duplicate clones a source File to this File's destination

func (*File) Init

func (f *File) Init(dir, name string)

Init handles the setup for a new File

func (*File) IsNewer

func (f *File) IsNewer(old *File) bool

IsNewer checks if the file was modified after a certain time

func (*File) Open

func (f *File) Open(flag int) error

Open this File, with the specified access flags

func (*File) Path

func (f *File) Path() string

Path gets the full filepath of the underlying file

func (*File) Read

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

Read retrieves data from this file (satisfies io.Reader)

func (*File) ReadString

func (f *File) ReadString() (raw string, err error)

ReadString reads the entire contents of this file as a string

func (*File) Stat

func (f *File) Stat() (changed bool, err error)

Stat updates the metadata for this File in memory

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

Write stores data into this file (satisfies io.Writer)

type Tree

type Tree struct {
	Root *Dir
}

Tree represents a generic file tree on disk

func NewTree

func NewTree(path string) (t *Tree, err error)

NewTree creates a Tree from the specified path, recursively

func (*Tree) Merge

func (t *Tree) Merge(other *Tree) (next *Tree, err error)

Merge combines two trees as if they had the same root

func (*Tree) Read

func (t *Tree) Read() (err error)

Read updates the contents of this Tree from disk

func (*Tree) Sub

func (t *Tree) Sub(name string) (sub *Tree, err error)

Sub provides a subtree of an immediate directory

Jump to

Keyboard shortcuts

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