fs

package
v0.0.0-...-e537141 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fs is built on top of the fs package of the go standard library.

Index

Constants

This section is empty.

Variables

View Source
var (
	EnsureFile = TypeEnsurer(path.TypeFile)
	EnsureDir  = TypeEnsurer(path.TypeDirectory)
)
View Source
var ErrNonMutFS = fmt.Errorf("fs/mut_fs.go: got a non a mutable filesystem (fs.MutFS)")

Functions

func ApplyIf

func ApplyIf(m MutFS, op BinaryOp, src, dst string) (supports bool, err error)

func Copy

func Copy(m MutFS, src, dst string) (err error)

func CreateAndUseFile

func CreateAndUseFile(fsys FS, path string, user UseWriter) (err error)

func EncodeToString

func EncodeToString(enc Encoding, src []byte) (s string)

func ExecuteBinOp

func ExecuteBinOp(mfs MutFS, def BinaryOpDef) error

func ExecuteBinOps

func ExecuteBinOps(fs FS, defs []BinaryOpDef) []error

func MkDirAllPerm

func MkDirAllPerm(mfs MutFS, path string, perm os.FileMode) (err error)

func Mkdir

func Mkdir(fsys fs.FS, path string, perm os.FileMode) error

func ModeToType

func ModeToType(mode fs.FileMode) (t path.Type)

func Move

func Move(m MutFS, src, dst string) (err error)

func MustMatch

func MustMatch(mode fs.FileMode, t path.Type) (err error)

func Open

func Open(fsys fs.FS, res Resource) (io.ReadCloser, error)

func OpenAndUseFile

func OpenAndUseFile(fsys FS, path string, user UseReader) (err error)

func Validate

func Validate(fsys FS, like path.Like) (err error)

Types

type BinaryOp

type BinaryOp int
const (
	// BinaryOpMove a file.
	BinaryOpMove BinaryOp = iota
	BinaryOpRename
	BinaryOpCopy
	BinaryOpLink
)

func (BinaryOp) Describe

func (b BinaryOp) Describe(one, two string) (s string)

func (BinaryOp) String

func (b BinaryOp) String() (s string)

func (BinaryOp) ToError

func (b BinaryOp) ToError(one, two string, err error) (be BinaryOpError)

type BinaryOpDef

type BinaryOpDef struct {
	File InOutFiles `json:"file"`
	Op   BinaryOp   `json:"op"`
}

type BinaryOpError

type BinaryOpError struct {
	// Binary operation that caused failure
	Op BinaryOp
	// The two arguments passed to the operation
	First, Second string
	// contains filtered or unexported fields
}

func (BinaryOpError) Error

func (b BinaryOpError) Error() (s string)

func (BinaryOpError) Unwrap

func (b BinaryOpError) Unwrap() (err error)

type BufReadCloser

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

func (BufReadCloser) Close

func (buf BufReadCloser) Close() error

func (BufReadCloser) Read

func (buf BufReadCloser) Read(b []byte) (int, error)

type BufWriteCloser

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

func (BufWriteCloser) Close

func (buf BufWriteCloser) Close() error

func (BufWriteCloser) Write

func (buf BufWriteCloser) Write(b []byte) (int, error)

type Buffer

type Buffer struct {
	Encoding string `json:"encoding"`
	Data     string `json:"data"`
}

func (Buffer) ResourceKind

func (Buffer) ResourceKind() ResourceKind

type BufferSizes

type BufferSizes struct {
	Write int
	Read  int
}

func DefaultBufferSize

func DefaultBufferSize() BufferSizes

func (BufferSizes) BufReader

func (bs BufferSizes) BufReader(r io.Reader) *bufio.Reader

func (BufferSizes) BufWriter

func (bs BufferSizes) BufWriter(w io.Writer) *bufio.Writer

type Encoding

type Encoding interface {
	EncodedLen(n int) int
	Encode(in, out []byte)
	DecodedLen(n int) int
	Decode(in, out []byte) (int, error)
}

type EnsureType

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

func TypeEnsurer

func TypeEnsurer(pathType path.Type) (e EnsureType)

func (EnsureType) ValidatePath

func (e EnsureType) ValidatePath(fsys FS, like string) (err error)

type FS

type FS fs.FS

type File

type File fs.File

func OpenDir

func OpenDir(fsys FS, pth string) (f File, err error)

func OpenFile

func OpenFile(fsys FS, pth string) (f File, err error)

type FileInfo

type FileInfo fs.FileInfo

type InOutFiles

type InOutFiles struct {
	In  string `json:"in"`
	Out string `json:"out"`
}

type Inputs

type Inputs map[string]Resource

func (*Inputs) UnmarshalJSON

func (in *Inputs) UnmarshalJSON(b []byte) error

type LogEncoding

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

TODO: add logging

func NewLogEncoding

func NewLogEncoding(encoding Encoding, log zerolog.Logger) (le LogEncoding)

func (LogEncoding) Decode

func (le LogEncoding) Decode(in, out []byte) (n int, err error)

func (LogEncoding) DecodedLen

func (le LogEncoding) DecodedLen(n int) int

func (LogEncoding) Encode

func (le LogEncoding) Encode(in, out []byte)

func (LogEncoding) EncodedLen

func (le LogEncoding) EncodedLen(n int) int

type Main

type Main struct {
	FS        FS
	BufWriter func(io.Writer) *bufio.Writer
	BufReader func(io.Reader) *bufio.Reader
}

func StdFS

func StdFS() Main

type MkDirAllFS

type MkDirAllFS interface {
	MutFS
	MkDirAll(name string, perm os.FileMode) error
}

MkDirAllFS is an extension interface to MutFS.

type MoveFs

type MoveFs interface {
	MutFS
	Move(from, to string) error
}

type MutFS

type MutFS interface {
	fs.FS
	// OpenMut Opens file for writing and changing the file's permissions.
	OpenMut(name string) (MutFile, error)
	// Create creates an empty file.
	Create(name string) (MutFile, error)
	// Remove removes a file from the filesystem.
	Remove(name string) error
	// Mkdir creates directory at the specified path.
	Mkdir(name string, perm os.FileMode) error
	// BinaryOp carries out an operation with two arguments
	BinaryOp(op BinaryOp, src, dst string) error
	// SupportsOp determines wether the filesystem support a given operation
	SupportsOp(op BinaryOp) bool
}

MutFS is the extended version of fs.FS that is capable of changing / mutating its structure.

type MutFile

type MutFile interface {
	fs.File
	Write(b []byte) (n int, err error)
	Chmod(os.FileMode) error
	Chown(uid, gid int) error
}

func Create

func Create(fsys fs.FS, path string) (mf MutFile, err error)

func OpenMut

func OpenMut(fsys fs.FS, path string) (mf MutFile, err error)

func Remove

func Remove(fsys fs.FS, path string) (mf MutFile, err error)

type MutOp

type MutOp int

ENUM(

Rename
Mkdir

)

type NoCloseReader

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

func (NoCloseReader) Close

func (NoCloseReader) Close() error

func (NoCloseReader) Read

func (n NoCloseReader) Read(b []byte) (int, error)

type NoCloseWriter

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

func (NoCloseWriter) Close

func (NoCloseWriter) Close() error

func (NoCloseWriter) Write

func (n NoCloseWriter) Write(b []byte) (int, error)

type OpError

type OpError struct {
	// Operation that caused failure
	Op Operation
	// The arguments passed to the operation
	Path path.Stringer
	// contains filtered or unexported fields
}

func (OpError) Error

func (e OpError) Error() (s string)

func (OpError) Unwrap

func (e OpError) Unwrap() (err error)

type OpenFunc

type OpenFunc func(fs.FS, Resource) (io.ReadCloser, error)

func WrapBuf

func WrapBuf(fn OpenFunc) OpenFunc

type Operation

type Operation int
const (
	OperationOpen Operation = iota
)

func (Operation) Describe

func (op Operation) Describe(p path.Stringer) (s string)

func (Operation) String

func (op Operation) String() (s string)

func (Operation) ToError

func (op Operation) ToError(p path.Stringer, err error) (e OpError)

type OsFS

type OsFS struct{}

OsFS represents a filesystem backed by the filesystem of the underlying OS.

func OS

func OS() *OsFS

OS returns a filesystem backed by the filesystem of the os. It wraps os.* stdlib operations.

func (OsFS) BinaryOp

func (f OsFS) BinaryOp(op BinaryOp, src, dst string) (err error)

func (OsFS) Create

func (OsFS) Create(name string) (f MutFile, err error)

func (OsFS) Glob

func (OsFS) Glob(name string) (matches []string, err error)

Glob wraps filepathpath.Glob.

func (OsFS) Mkdir

func (OsFS) Mkdir(name string, perm os.FileMode) (err error)

Mkdir wraps os.Mkdir.

func (OsFS) MkdirAll

func (OsFS) MkdirAll(name string, perm os.FileMode) (err error)

MkdirAll wraps os.MkdirAll.

func (OsFS) Open

func (OsFS) Open(name string) (f fs.File, err error)

Open wraps os.Open.

func (OsFS) OpenMut

func (OsFS) OpenMut(name string) (f MutFile, err error)

func (OsFS) Remove

func (OsFS) Remove(name string) (err error)

Remove wraps os.Remove.

func (OsFS) Rename

func (OsFS) Rename(oldpath, newpath string) (err error)

Rename wraps os.Rename.

func (OsFS) SupportsOp

func (f OsFS) SupportsOp(op BinaryOp) (ok bool)

type Path

type Path struct {
	Path string `json:"path"`
}

func (Path) ResourceKind

func (Path) ResourceKind() ResourceKind

type Resource

type Resource interface {
	ResourceKind() ResourceKind
}

type ResourceID

type ResourceID string

type ResourceKind

type ResourceKind int

ENUM(

Path
Buffer

)

const (
	ResourcePath ResourceKind = iota
	ResourceBuffer
)

type UnsupportedBinaryOpError

type UnsupportedBinaryOpError struct {
	Op BinaryOp
}

func (*UnsupportedBinaryOpError) Error

func (e *UnsupportedBinaryOpError) Error() string

type UseReader

type UseReader func(r io.Reader) (err error)

type UseWriter

type UseWriter func(w io.Writer) (err error)

type ValidateFS

type ValidateFS interface {
	FS
	Validate(path.Like) error
}

type ValidatedFS

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

func Validated

func Validated(fsys FS, valid Validator) (v ValidatedFS)

func (ValidatedFS) Open

func (v ValidatedFS) Open(name string) (f File, err error)

func (ValidatedFS) Validate

func (v ValidatedFS) Validate(like string) (err error)

type Validator

type Validator interface {
	ValidatePath(FS, string) error
}

Jump to

Keyboard shortcuts

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