Help us shape the future of Go! Take the 2026 Go Developer Survey

filework

package module
v0.0.0-...-4a619ea Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 6 Imported by: 1

README

filework Go Reference

The filework project provides file system abstraction and operations for Go.

This project was written before the fs package was added to Go's standard library. It's preserved here for the sake of projects that depend on it.

It's possible that filework will be reworked to make use of the fs package in the future.

Documentation

Overview

Package filework provides file system abstraction and operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExistingDirectory is returned when a directory is found where a file
	// was expected.
	ErrExistingDirectory = errors.New("a directory exists where a file was expected")

	// ErrExistingFile is returned when a file is found where a directory
	// was expected.
	ErrExistingFile = errors.New("a file exists where a directory was expected")

	// ErrBadDirectory is returned when a file is found where a directory
	// was expected.
	ErrBadDirectory = errors.New("a file does not implement the directory interface despite being marked as a directory")
)

Functions

func CompareContent

func CompareContent(a, b io.Reader) (same bool, err error)

CompareContent compares the content of two readers. It returns true if the content is the same.

Types

type Action

type Action struct {
	SourcePath string
	DestPath   string
	Op         Op
}

Action describes an action taken.

type Comparison

type Comparison int

Comparison describes the difference between two files.

const (
	Different Comparison = 0
	Missing   Comparison = 1
	Same      Comparison = 2
)

Comparison constants.

func CompareFileContent

func CompareFileContent(content io.Reader, fs FileSystem, path string) (Comparison, error)

CompareFileContent compares content with a destination file system.

If content implements io.Seeker, a seek to the start of content will be performed before and after a comparison is performed. NOTE: This behavior is subject to change in future revisions.

func (Comparison) String

func (c Comparison) String() string

String returns a string representation of the comparison.

type Dir

type Dir interface {
	Readdir(count int) ([]os.FileInfo, error)
}

Dir is the minimum interface required to read directories.

type File

type File interface {
	io.Reader
	io.Seeker
	Stat() (os.FileInfo, error)
}

File is the minimum interface required to read files.

type FileSystem

type FileSystem interface {
	Open(name string) (File, error)
	Stat(name string) (os.FileInfo, error)
}

FileSystem is the minimum interface required to read from a file system.

type FileSystemWriter

type FileSystemWriter interface {
	FileSystem
	Create(name string) (FileWriter, error)
	Remove(path string) error
	RemoveAll(path string) error
	MkdirAll(path string, perm os.FileMode) error
}

FileSystemWriter is the minimum interface required to write to a file system.

type FileWriter

type FileWriter interface {
	File
	Write(b []byte) (n int, err error)
}

FileWriter is the minimum interface required to write files.

type Joiner

type Joiner interface {
	Join(elem ...string) string
}

A Joiner is a file system capable of joining paths.

type Locker

type Locker interface {
	Lock() error
	Unlock() error
}

A Locker is a file capable of locking.

type Log

type Log []Result

A Log is a set of file copy results.

func CopyDir

func CopyDir(sourceFS FileSystem, sourcePath string, source Dir, destFS FileSystemWriter, destPath string, destPerms os.FileMode) (lg Log)

CopyDir copies a directory and all of its contents.

TODO: Determine content copying by option? TODO: Determine perms by option?

TODO: Receive a context?

func CopyPath

func CopyPath(sourceFS FileSystem, sourcePath string, destFS FileSystemWriter, destPath string) (lg Log)

CopyPath copies a file or directory described by path from source to dest and returns a log of its actions.

TODO: Allow the user to specify perms for directories?

func (Log) Err

func (lg Log) Err() error

Err returns the first error in the log if one exists, or nil.

type Namer

type Namer interface {
	Name() string
}

A Namer is a file capable of reporting its name.

type Op

type Op uint32

Op is a filework operation.

const (
	CopyOperation Op = 1
)

Filework operations.

type Outcome

type Outcome int

Outcome holds the outcome of an attempted action on a file or set of files.

const (
	Unchanged Outcome = 0
	Created   Outcome = 1
	Modified  Outcome = 2
	Deleted   Outcome = 3
)

Outcome constants.

func CopyFileContent

func CopyFileContent(content io.Reader, fs FileSystemWriter, path string) (Outcome, error)

CopyFileContent copies data from content to fs and reports the outcome.

func (Outcome) String

func (outcome Outcome) String() string

String returns a string of the outcome type.

type Result

type Result struct {
	Action
	os.FileMode
	Outcome Outcome
	Err     error
}

Result is the result of a filework operation.

func CopyFile

func CopyFile(sourceFS FileSystem, sourcePath string, source File, destFS FileSystemWriter, destPath string) Result

CopyFile copies data from source to dest.

type Syncer

type Syncer interface {
	Sync() error
}

A Syncer is a file capable of flushing its data to stable storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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