fs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package fs inclues a filesystem that can read from a local directory or S3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(ctx context.Context, input *CopyInput) error

Copy copies a file from the input file system to the output file system

func EqualTimestamp

func EqualTimestamp(a time.Time, b time.Time, d time.Duration) bool

EqualTimestamp returns true if time a and b are equal after being truncated. When syncing between a source and destination filesystem with different precision for their last modified timestamps, this function can be used to confirm the stored timestamps are equivalent.

func Sync

func Sync(ctx context.Context, input *SyncInput) (int, error)

func SyncDirectory

func SyncDirectory(ctx context.Context, input *SyncDirectoryInput) (int, error)

Types

type CopyInput

type CopyInput struct {
	CheckParents          bool
	SourceName            string
	SourceFileInfo        FileInfo
	SourceFileSystem      FileSystem
	DestinationName       string
	DestinationFileInfo   FileInfo
	DestinationFileSystem FileSystem
	Logger                Logger
	MakeParents           bool
}

type DirectoryEntry

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

func NewDirectoryEntry

func NewDirectoryEntry(name string, dir bool, modTime time.Time, size int64) *DirectoryEntry

func (*DirectoryEntry) IsDir

func (de *DirectoryEntry) IsDir() bool

func (*DirectoryEntry) MarshalJSON

func (de *DirectoryEntry) MarshalJSON() ([]byte, error)

func (*DirectoryEntry) ModTime

func (de *DirectoryEntry) ModTime() time.Time

func (*DirectoryEntry) Name

func (de *DirectoryEntry) Name() string

func (*DirectoryEntry) Size

func (de *DirectoryEntry) Size() int64

func (*DirectoryEntry) String

func (de *DirectoryEntry) String() string

type DirectoryEntryInterface

type DirectoryEntryInterface interface {
	IsDir() bool
	MarshalJSON() ([]byte, error)
	ModTime() time.Time
	Name() string
	Size() int64
	String() string
}

type File

type File interface {
	io.ReadSeekCloser
	io.WriteCloser
	io.WriterAt
	Name() string
	WriteTo(ctx context.Context, w Writer) (int64, error)
}

type FileInfo

type FileInfo interface {
	IsDir() bool
	Name() string
	ModTime() time.Time
	Size() int64
	String() string
}

type FileSystem

type FileSystem interface {
	Chtimes(ctx context.Context, name string, atime time.Time, mtime time.Time) error
	Copy(ctx context.Context, input *CopyInput) error
	Dir(name string) string
	IsNotExist(err error) bool
	Join(name ...string) string
	MagicNumber(ctx context.Context, name string) ([]byte, error)
	MagicNumbers(ctx context.Context, names []string, threads int) ([][]byte, error)
	MkdirAll(ctx context.Context, name string, mode os.FileMode) error
	MustRelative(ctx context.Context, basepath string, targetpath string) string
	Open(ctx context.Context, name string) (Object, error)
	OpenObject(ctx context.Context, name string, flag int, perm os.FileMode) (Object, error)
	Relative(ctx context.Context, basepath string, targetpath string) (string, error)
	ReadDir(ctx context.Context, name string, recursive bool) ([]DirectoryEntryInterface, error)
	ReadFile(ctx context.Context, name string, p []byte) (n int, err error) // open up a file and read the contents
	RemoveFile(ctx context.Context, name string) error
	RemoveFiles(ctx context.Context, names []string) error
	RemoveDirectory(ctx context.Context, name string, recursive bool) error
	RemoveDirectories(ctx context.Context, name []string, recursive bool) error
	Root() string
	Size(ctx context.Context, name string) (int64, error)
	Stat(ctx context.Context, name string) (FileInfo, error)
	Sync(ctx context.Context, input *SyncInput) (int, error)
	SyncDirectory(ctx context.Context, input *SyncDirectoryInput) (int, error)
}

type Logger

type Logger interface {
	Log(msg string, fields ...map[string]interface{}) error
}

type Object

type Object interface {
	io.ReadSeekCloser
	io.WriteCloser
	Name() string
	WriteTo(ctx context.Context, w Writer) (int64, error)
}

type SyncDirectoryInput

type SyncDirectoryInput struct {
	Delete                bool
	CheckTimestamps       bool
	DestinationDirectory  string
	DestinationFileSystem FileSystem
	Exclude               []string
	Limit                 int
	Logger                Logger
	MaxThreads            int
	SourceDirectory       string
	SourceFileSystem      FileSystem
	TimestampPrecision    time.Duration
}

type SyncInput

type SyncInput struct {
	Delete                bool
	Source                string // could be file or directory
	SourceFileSystem      FileSystem
	Destination           string // could be file or directory
	Exclude               []string
	DestinationFileSystem FileSystem
	Parents               bool
	CheckTimestamps       bool
	Limit                 int
	Logger                Logger
	MaxThreads            int
	TimestampPrecision    time.Duration
}

type Writer

type Writer interface {
	io.WriteCloser
}

type WriterAt

type WriterAt interface {
	Writer
	io.WriterAt
}

Jump to

Keyboard shortcuts

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