file

package
v0.0.0-...-2be0f72 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OS osOperations

OS allows access to the os package methods that are the same as in the Operations interface.

Functions

func Checksum32

func Checksum32(path string) uint32

Checksum32 create a crc32 checksum for file at path.

func Copy

func Copy(src, dest string) error

Copy copies a file from src to dest.

func Equal

func Equal(fid1, fid2 FID) bool

Equal compares to FIDs for equality. It can be used to check if a file has changed.

func ExInfoFrom

func ExInfoFrom(size int64, ctime, atime, mtime time.Time, fid FID) *stdExFileInfo

func Exists

func Exists(path string) bool

Exists returns true if path exists.

func Hash

func Hash(hasher hash.Hash, path string) ([]byte, error)

Hash creates a hash on file path path using the specified Hash.

func HashStr

func HashStr(hasher hash.Hash, path string) (string, error)

HashStr creates a hexadecimal string of the hash of the file at path using the specified Hash.

func IsDir

func IsDir(path string) bool

IsDir returns true if path is a directory.

func NormalizePath

func NormalizePath(path string) string

NormalizePath converts all slashes in a path to '/' (forward) slashes

Types

type ExFileInfo

type ExFileInfo interface {
	os.FileInfo       // Support the os.FileInfo interface
	Path() string     // Full path of file
	CTime() time.Time // Creation time
	ATime() time.Time // Last access time
	FID() FID         // System independent File ID
}

ExFileInfo is an extended version of the os.FileInfo interface that includes additional information.

func ExStat

func ExStat(path string) (fileInfo ExFileInfo, err error)

ExStat is an extended version of the os.Stat() method.

func ExStatFromFileInfo

func ExStatFromFileInfo(fi os.FileInfo, path string) (ExFileInfo, error)

ExStatFromFileInfo takes a os.FileInfo and a path and returns an ExFileInfo.

type FID

type FID struct {
	IDLow  uint64
	IDHigh uint64
}

FID represents a file identifier. On Linux it is the INode. On Windows it is the file index and volume serial number.

type MockFileInfo

type MockFileInfo struct {
	MName    string
	MSize    int64
	MMode    os.FileMode
	MModTime time.Time
	MIsDir   bool
	MSys     interface{}
}

func (MockFileInfo) IsDir

func (fi MockFileInfo) IsDir() bool

func (MockFileInfo) ModTime

func (fi MockFileInfo) ModTime() time.Time

func (MockFileInfo) Mode

func (fi MockFileInfo) Mode() os.FileMode

func (MockFileInfo) Name

func (fi MockFileInfo) Name() string

func (MockFileInfo) Size

func (fi MockFileInfo) Size() int64

func (MockFileInfo) Sys

func (fi MockFileInfo) Sys() interface{}

type MockFileOpEntry

type MockFileOpEntry struct {
	Err    error
	RValue interface{}
}

type MockOperations

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

func MockOps

func MockOps() *MockOperations

func (*MockOperations) Create

func (m *MockOperations) Create(path string) (*os.File, error)

Create returns nil, Err from MockOps if MockOps Err is not nil. Otherwise it returns os.Create(os.DevNull).

func (*MockOperations) Mkdir

func (m *MockOperations) Mkdir(path string, perm os.FileMode) error

Mkdir returns Err from MockOps. It does nothing.

func (*MockOperations) MkdirAll

func (m *MockOperations) MkdirAll(path string, perm os.FileMode) error

MkdirAll returns Err from MockOps. It does nothing.

func (*MockOperations) On

func (m *MockOperations) On(method string) *MockOperations

func (*MockOperations) Open

func (m *MockOperations) Open(path string) (*os.File, error)

Open returns nil, Err from MockOps if MockOps err is not nil. Otherwise it returns os.Open(os.DevNull).

func (*MockOperations) Remove

func (m *MockOperations) Remove(path string) error

Remove returns Err from MockOps. It does nothing.

func (*MockOperations) RemoveAll

func (m *MockOperations) RemoveAll(path string) error

RemoveAll returns Err from MockOps. It does nothing.

func (*MockOperations) Rename

func (m *MockOperations) Rename(oldpath, newpath string) error

Rename returns Err from MockOps. It does nothing.

func (*MockOperations) SetError

func (m *MockOperations) SetError(err error) *MockOperations

func (*MockOperations) SetValue

func (m *MockOperations) SetValue(what interface{}) *MockOperations

func (*MockOperations) Stat

func (m *MockOperations) Stat(path string) (os.FileInfo, error)

type Operations

type Operations interface {
	Remove(path string) error
	RemoveAll(path string) error
	Mkdir(path string, perm os.FileMode) error
	MkdirAll(path string, perm os.FileMode) error
	Create(path string) (*os.File, error)
	Open(name string) (file *os.File, err error)
	Rename(oldpath, newpath string) error
	Stat(path string) (os.FileInfo, error)
}

Operations is the operations on a file. The interface exists to allow mocking of file system operations.

type TarReader

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

TarReader type contains all the artifacts needed to unpack a tar file.

func NewTar

func NewTar(path string) (*TarReader, error)

NewTar creates a new TarReader.

func NewTarGz

func NewTarGz(path string) (*TarReader, error)

NewTarGz create a new TarReader for a tar file that has been gzipped.

func (*TarReader) Unpack

func (tr *TarReader) Unpack(toPath string) error

Unpack will unpack a tar file contained in the TarReader. It writes the new entires to the toPath. Unpack takes care of closing the underlying artifacts (file, and gzip stream) for the TarReader. You cannot call Unpack twice for the same TarReader.

Jump to

Keyboard shortcuts

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