flo

package module
v0.0.0-...-869b69f Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Unlicense Imports: 23 Imported by: 1

README

FLO (File Layer Operations)

... is a Go library to simplify working with files and directories. Feel free to use or fork it, if it works for you.

It is intended to be fast to use with a certain degree of flexibility.

Examples

ls -lha

You can find an implementation of ls -lha with some additional features here.

examples/codecs/main.go

A test application for reading and writing data using the different formats supported. Also tests checksum comparisons.

examples/exec/main.go

A simple application that can execute another application.

examples/flat-tree/main.go

A tool that can list all files and directories contained in a directory. Recursion depth can be limited.

examples/hello/main.go

An example that shows how to create a script on the fly, make it executable and execute it.

examples/ls/main.go

An example that acts like a call to ls.

examples/tree/main.go

Similar to the flat-tree example, but displays a tree structure instead, just like good ol' tree.

Logging

There are a few cases where the library logs, in those cases it will use the Error and Panic functions found in log/main.go. You can overwrite these functions to handle errors yourself, e.g. to ignore errors:

// silence all logging
log.SetFns(nil, nil) 

// no errors, custom panic handler
log.SetFns(nil, func(fmtStr string, args ...any) { panic(fmt.Sprintf("lib died: "+fmtStr, args...)) })

// no panics, custom error handler
log.SetFns(func(err error, fmtStr string, args ...any) (shouldReturn bool) { fmt.Println("Error", err.Error()) ; return err != nil }, nil)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirObj

type DirObj struct {
	*FileObj
	// contains filtered or unexported fields
}

func Dir

func Dir(path string) *DirObj

func (*DirObj) Contents

func (d *DirObj) Contents() *DirObj

func (*DirObj) Dirs

func (d *DirObj) Dirs() []*DirObj

func (*DirObj) Each

func (d *DirObj) Each(fnFile func(f *FileObj), fnDir func(d *DirObj))

func (*DirObj) EachLimit

func (d *DirObj) EachLimit(fnFile func(f *FileObj), fnDir func(d *DirObj), maxDepth int)

func (*DirObj) Files

func (d *DirObj) Files() []*FileObj

func (*DirObj) InitWithEmbeddedFS

func (dir *DirObj) InitWithEmbeddedFS(embeddedFS embed.FS, pathPrefix string, dirMode, fileMode fs.FileMode) error

InitWithEmbeddedFS unpacks the given `embeddedFS` into this directory.

It will first remove the directory if it exists and then create it to ensure that we start with a clean slate.

If your embedded FS contains a path prefix (e.g. `//go:embed mysource/*`) and you don't want that replicated when extracting the FS, you can provide it as `pathPrefix` to strip it (e.g. `pathPrefix = "mysource"`).

Be aware that embedded filesystems do not store file permissions. Therefore all dirs and files will be written with the provided permissions `dirMode` and `fileMode` respectively.

func (*DirObj) UpdateFromEmbeddedFS

func (dir *DirObj) UpdateFromEmbeddedFS(embeddedFS embed.FS, pathPrefix string, dirMode, fileMode fs.FileMode, overwriteExisting bool) error

UpdateFromEmbeddedFS works similar to InitWithEmbeddedFS but will not clear the directory before extracting the embedded FS.

Existing files will only be overwritten with the version in the embedded FS if you set `overwriteExisting` to `true`.

type FileInfo

type FileInfo struct {
	Name         string
	Exists       bool
	LastModified time.Time
	Mode         fs.FileMode
	Size         int64
	Path         string
	Checksum     *checksum.Checksum
	Permissions  *permissions.Permissions
	Ownership    *ownership.FileOwnership
}

func (*FileInfo) NewerThan

func (f *FileInfo) NewerThan(t time.Time) bool

func (*FileInfo) OlderThan

func (f *FileInfo) OlderThan(t time.Time) bool

func (*FileInfo) String

func (f *FileInfo) String(maxLenOwner, maxLenGroup int) string

type FileObj

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

func File

func File(path string) *FileObj

func (*FileObj) AsBase64Std

func (f *FileObj) AsBase64Std() string

func (*FileObj) AsBase64URL

func (f *FileObj) AsBase64URL() string

func (*FileObj) AsBytes

func (f *FileObj) AsBytes() []byte

func (*FileObj) AsBytesGZ

func (f *FileObj) AsBytesGZ() []byte

func (*FileObj) AsString

func (f *FileObj) AsString() string

func (*FileObj) AsStringGZ

func (f *FileObj) AsStringGZ() string

func (*FileObj) AsURL

func (f *FileObj) AsURL() string

func (*FileObj) BaseDir

func (f *FileObj) BaseDir() string

func (*FileObj) CRC32

func (f *FileObj) CRC32() string

func (*FileObj) CRC64

func (f *FileObj) CRC64() string

func (*FileObj) Checksum

func (f *FileObj) Checksum() *checksum.Checksum

func (*FileObj) Copy

func (f *FileObj) Copy(destinationPath string) error

func (*FileObj) CopyFrom

func (f *FileObj) CopyFrom(file *FileObj) error

func (*FileObj) Create

func (f *FileObj) Create(perm fs.FileMode) error

func (*FileObj) Depth

func (f *FileObj) Depth() int

func (*FileObj) Dir

func (f *FileObj) Dir(name string) *DirObj

func (*FileObj) Exec

func (f *FileObj) Exec(args ...any) error

func (*FileObj) ExecBackground

func (f *FileObj) ExecBackground(args ...any) error

func (*FileObj) ExecOutput

func (f *FileObj) ExecOutput(args ...any) ([]byte, error)

func (*FileObj) ExecQuiet

func (f *FileObj) ExecQuiet(args ...any) error

func (*FileObj) Exists

func (f *FileObj) Exists() bool

func (*FileObj) File

func (f *FileObj) File(name string) *FileObj

func (*FileObj) FileMode

func (f *FileObj) FileMode() fs.FileMode

func (*FileObj) Group

func (f *FileObj) Group() string

func (*FileObj) Info

func (f *FileObj) Info() *FileInfo

func (*FileObj) IsExecutable

func (f *FileObj) IsExecutable() bool

func (*FileObj) IsExecutableGroup

func (f *FileObj) IsExecutableGroup() bool

func (*FileObj) IsExecutableOwner

func (f *FileObj) IsExecutableOwner() bool

func (*FileObj) IsExecutableWorld

func (f *FileObj) IsExecutableWorld() bool

func (*FileObj) IsReadable

func (f *FileObj) IsReadable() bool

func (*FileObj) IsReadableGroup

func (f *FileObj) IsReadableGroup() bool

func (*FileObj) IsReadableOwner

func (f *FileObj) IsReadableOwner() bool

func (*FileObj) IsReadableWorld

func (f *FileObj) IsReadableWorld() bool

func (*FileObj) IsWritable

func (f *FileObj) IsWritable() bool

func (*FileObj) IsWritableGroup

func (f *FileObj) IsWritableGroup() bool

func (*FileObj) IsWritableOwner

func (f *FileObj) IsWritableOwner() bool

func (*FileObj) IsWritableWorld

func (f *FileObj) IsWritableWorld() bool

func (*FileObj) LastModified

func (f *FileObj) LastModified() time.Time

func (*FileObj) LoadBase64Std

func (f *FileObj) LoadBase64Std(target any) error

func (*FileObj) LoadBase64URL

func (f *FileObj) LoadBase64URL(target any) error

func (*FileObj) LoadBytes

func (f *FileObj) LoadBytes(target *[]byte) error

func (*FileObj) LoadBytesGZ

func (f *FileObj) LoadBytesGZ(target *[]byte) error

func (*FileObj) LoadGob

func (f *FileObj) LoadGob(target any) error

func (*FileObj) LoadGobGZ

func (f *FileObj) LoadGobGZ(target any) error

func (*FileObj) LoadJSON

func (f *FileObj) LoadJSON(target any) error

func (*FileObj) LoadString

func (f *FileObj) LoadString(target *string) error

func (*FileObj) LoadStringGZ

func (f *FileObj) LoadStringGZ(target *string) error

func (*FileObj) LoadURL

func (f *FileObj) LoadURL(target any) error

func (*FileObj) LoadYAML

func (f *FileObj) LoadYAML(target any) error

func (*FileObj) MD5

func (f *FileObj) MD5() string

func (*FileObj) Mkdir

func (f *FileObj) Mkdir(mode fs.FileMode) error
func (f *FileObj) Mklink(path string) error

Mklink creates a symlink at the given path pointing this file's path

func (*FileObj) Mkparent

func (f *FileObj) Mkparent(perm fs.FileMode) error

func (*FileObj) MustReadCRC32

func (f *FileObj) MustReadCRC32(target *string) *FileObj

func (*FileObj) MustReadCRC64

func (f *FileObj) MustReadCRC64(target *string) *FileObj

func (*FileObj) MustReadMD5

func (f *FileObj) MustReadMD5(target *string) *FileObj

func (*FileObj) MustReadSHA1

func (f *FileObj) MustReadSHA1(target *string) *FileObj

func (*FileObj) MustReadSHA256

func (f *FileObj) MustReadSHA256(target *string) *FileObj

func (*FileObj) MustReadSHA512

func (f *FileObj) MustReadSHA512(target *string) *FileObj

func (*FileObj) Name

func (f *FileObj) Name() string

func (*FileObj) NewerThan

func (f *FileObj) NewerThan(t time.Time) bool

func (*FileObj) OlderThan

func (f *FileObj) OlderThan(t time.Time) bool

func (*FileObj) Open

func (f *FileObj) Open() (file *os.File, closer func())

func (*FileObj) OpenAppend

func (f *FileObj) OpenAppend() (file *os.File, closer func())

OpenAppend opens the file for appending, creating the file if it doesn't exist.

func (*FileObj) OpenReadOnly

func (f *FileObj) OpenReadOnly() (file *os.File, closer func())

func (*FileObj) OpenTruncate

func (f *FileObj) OpenTruncate() (file *os.File, closer func())

OpenTruncate opens the file for writing, creating the file if it doesn't exist. The file will be truncated if it exists.

func (*FileObj) OpenWriteOnly

func (f *FileObj) OpenWriteOnly() (file *os.File, closer func())

func (*FileObj) Own

func (f *FileObj) Own(username string) error

func (*FileObj) Owner

func (f *FileObj) Owner() string

func (*FileObj) Parent

func (f *FileObj) Parent() *DirObj

func (*FileObj) Path

func (f *FileObj) Path() string

func (*FileObj) Perm

func (f *FileObj) Perm(mode fs.FileMode) error

func (*FileObj) PermExec

func (f *FileObj) PermExec(owner, group, world bool) *FileObj

func (*FileObj) PermExecAll

func (f *FileObj) PermExecAll() *FileObj

func (*FileObj) PermGroup

func (f *FileObj) PermGroup(r, w, x bool) *FileObj

func (*FileObj) PermOwner

func (f *FileObj) PermOwner(r, w, x bool) *FileObj

func (*FileObj) PermRead

func (f *FileObj) PermRead(owner, group, world bool) *FileObj

func (*FileObj) PermReadAll

func (f *FileObj) PermReadAll() *FileObj

func (*FileObj) PermWorld

func (f *FileObj) PermWorld(r, w, x bool) *FileObj

func (*FileObj) PermWrite

func (f *FileObj) PermWrite(owner, group, world bool) *FileObj

func (*FileObj) PermWriteAll

func (f *FileObj) PermWriteAll() *FileObj

func (*FileObj) Permissions

func (f *FileObj) Permissions() *permissions.Permissions

func (*FileObj) ReadBase64Std

func (f *FileObj) ReadBase64Std(target any) *FileObj

func (*FileObj) ReadBase64URL

func (f *FileObj) ReadBase64URL(target any) *FileObj

func (*FileObj) ReadBytes

func (f *FileObj) ReadBytes(target *[]byte) *FileObj

func (*FileObj) ReadBytesGZ

func (f *FileObj) ReadBytesGZ(target *[]byte) *FileObj

func (*FileObj) ReadCRC32

func (f *FileObj) ReadCRC32(target *string) error

func (*FileObj) ReadCRC64

func (f *FileObj) ReadCRC64(target *string) error

func (*FileObj) ReadGob

func (f *FileObj) ReadGob(target any) *FileObj

func (*FileObj) ReadGobGZ

func (f *FileObj) ReadGobGZ(target any) *FileObj

func (*FileObj) ReadJSON

func (f *FileObj) ReadJSON(target any) *FileObj

func (*FileObj) ReadMD5

func (f *FileObj) ReadMD5(target *string) error

func (*FileObj) ReadSHA1

func (f *FileObj) ReadSHA1(target *string) error

func (*FileObj) ReadSHA256

func (f *FileObj) ReadSHA256(target *string) error

func (*FileObj) ReadSHA512

func (f *FileObj) ReadSHA512(target *string) error

func (*FileObj) ReadString

func (f *FileObj) ReadString(target *string) *FileObj

func (*FileObj) ReadStringGZ

func (f *FileObj) ReadStringGZ(target *string) *FileObj

func (*FileObj) ReadURL

func (f *FileObj) ReadURL(target any) *FileObj

func (*FileObj) ReadYAML

func (f *FileObj) ReadYAML(target any) *FileObj

func (*FileObj) Remove

func (f *FileObj) Remove() error

func (*FileObj) RenderFromTemplate

func (f *FileObj) RenderFromTemplate(tmpl string, data any, fns template.FuncMap) error

func (*FileObj) SHA1

func (f *FileObj) SHA1() string

func (*FileObj) SHA256

func (f *FileObj) SHA256() string

func (*FileObj) SHA512

func (f *FileObj) SHA512() string

func (*FileObj) SameAs

func (f *FileObj) SameAs(file *FileObj) bool

func (*FileObj) SameCRC32As

func (f *FileObj) SameCRC32As(file *FileObj) bool

func (*FileObj) SameCRC64As

func (f *FileObj) SameCRC64As(file *FileObj) bool

func (*FileObj) SameMD5As

func (f *FileObj) SameMD5As(file *FileObj) bool

func (*FileObj) SameSHA1As

func (f *FileObj) SameSHA1As(file *FileObj) bool

func (*FileObj) SameSHA256As

func (f *FileObj) SameSHA256As(file *FileObj) bool

func (*FileObj) SameSHA512As

func (f *FileObj) SameSHA512As(file *FileObj) bool

func (*FileObj) Size

func (f *FileObj) Size() int64

func (*FileObj) StoreBase64Std

func (f *FileObj) StoreBase64Std(data any) error

func (*FileObj) StoreBase64URL

func (f *FileObj) StoreBase64URL(data any) error

func (*FileObj) StoreBytes

func (f *FileObj) StoreBytes(data []byte) error

func (*FileObj) StoreBytesGZ

func (f *FileObj) StoreBytesGZ(data []byte) error

func (*FileObj) StoreGob

func (f *FileObj) StoreGob(data any) error

func (*FileObj) StoreGobGZ

func (f *FileObj) StoreGobGZ(data any) error

func (*FileObj) StoreJSON

func (f *FileObj) StoreJSON(data any) error

func (*FileObj) StoreString

func (f *FileObj) StoreString(data string) error

func (*FileObj) StoreStringGZ

func (f *FileObj) StoreStringGZ(data string) error

func (*FileObj) StoreURL

func (f *FileObj) StoreURL(data any) error

func (*FileObj) StoreYAML

func (f *FileObj) StoreYAML(data any) error

func (*FileObj) String

func (f *FileObj) String(lenOwner, lenGroup int) string

func (*FileObj) WriteBase64Std

func (f *FileObj) WriteBase64Std(data any) *FileObj

func (*FileObj) WriteBase64URL

func (f *FileObj) WriteBase64URL(data any) *FileObj

func (*FileObj) WriteBytes

func (f *FileObj) WriteBytes(data []byte) *FileObj

func (*FileObj) WriteBytesGZ

func (f *FileObj) WriteBytesGZ(data []byte) *FileObj

func (*FileObj) WriteGob

func (f *FileObj) WriteGob(data any) *FileObj

func (*FileObj) WriteGobGZ

func (f *FileObj) WriteGobGZ(data any) *FileObj

func (*FileObj) WriteJSON

func (f *FileObj) WriteJSON(data any) *FileObj

func (*FileObj) WriteString

func (f *FileObj) WriteString(data string) *FileObj

func (*FileObj) WriteStringGZ

func (f *FileObj) WriteStringGZ(data string) *FileObj

func (*FileObj) WriteURL

func (f *FileObj) WriteURL(data any) *FileObj

func (*FileObj) WriteYAML

func (f *FileObj) WriteYAML(data any) *FileObj

Directories

Path Synopsis
examples
ls

Jump to

Keyboard shortcuts

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