memory

package
v0.0.0-...-be7858c Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package memory implements the file tree interface (tree.Entry). All data is stored in memory. This implementation is mostly intended for testing purposes.

Index

Constants

View Source
const (
	DEFAULT_MODE     = 0644
	DEFAULT_DIR_MODE = 0755
	DEFAULT_HAS_MODE = 0777
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

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

Entry is one file or directory.

func NewRoot

func NewRoot() *Entry

NewRoot creates a new in-memory filesystem root.

func (*Entry) Chmod

func (e *Entry) Chmod(target, source tree.FileInfo) (tree.FileInfo, error)

Chmod applies the given mode bits, as far as this in-memory tree 'supports' them.

func (*Entry) Close

func (e *Entry) Close() error

Close does nothing: there are no resources allocated that won't be collected by the garbage collector.

func (*Entry) CopySource

func (e *Entry) CopySource(source tree.FileInfo) (io.ReadCloser, error)

CopySource creates a bytes.Buffer reader to read the contents of this file.

func (*Entry) CreateDir

func (e *Entry) CreateDir(name string, parentInfo, sourceInfo tree.FileInfo) (tree.FileInfo, error)

CreateDir creates a directory with the given name.

func (*Entry) CreateFile

func (e *Entry) CreateFile(name string, parent, source tree.FileInfo) (tree.Copier, error)

CreateFile is part of tree.FileEntry. It returns the created entry, a WriteCloser to write the data to, and possibly an error. The file's contents is stored when the returned WriteCloser is closed.

func (e *Entry) CreateSymlink(name string, parentInfo, sourceInfo tree.FileInfo, contents string) (tree.FileInfo, tree.FileInfo, error)

CreateSymlink creates an Entry with type link and the contents.

func (*Entry) FullInfo

func (e *Entry) FullInfo() (tree.FileInfo, error)

FullInfo returns a FileInfo object with hash. It won't return an error (there are no IO errors in an in-memory filesystem).

func (*Entry) GetFile

func (e *Entry) GetFile(name string) (io.ReadCloser, error)

GetFile returns a file handle (io.ReadCloser) that can be used to read a status file.

func (*Entry) HasMode

func (e *Entry) HasMode() tree.Mode

HasMode returns the supported mode bits, currently 0777.

func (*Entry) Hash

func (e *Entry) Hash() (tree.Hash, error)

Hash returns the blake2b hash of this file.

func (*Entry) Id

func (e *Entry) Id() (uint64, *tree.LocalFilesystem)

Id returns the inode and dummy filesystem information.

func (*Entry) Info

func (e *Entry) Info() tree.FileInfo

Info returns a FileInfo object without a hash.

func (*Entry) List

func (e *Entry) List(options tree.ListOptions) ([]tree.Entry, error)

List returns a list of directory entries for directories. It returns an error when attempting to list something other than a directory.

func (*Entry) ModTime

func (e *Entry) ModTime() time.Time

ModTime returns the modification or creation time.

func (*Entry) Mode

func (e *Entry) Mode() tree.Mode

Mode returns the mode permission bits.

func (*Entry) Name

func (e *Entry) Name() string

Name returns the filename (not the path)

func (*Entry) PutFile

func (e *Entry) PutFile(name string) (tree.Copier, error)

PutFile returns a file handle (tree.Copier) to a newly created/replaced child file that can be used to save the replica state.

func (*Entry) PutFileTest

func (e *Entry) PutFileTest(path []string, contents []byte) (tree.FileInfo, error)

PutFileTest writes the contents to a new or existing file. This function only exists for testing purposes.

func (*Entry) ReadInfo

func (e *Entry) ReadInfo(path []string) (tree.FileInfo, error)

ReadInfo returns the FileInfo for the specified file, with a hash, or a 'not found' error if the file doesn't exist.

func (e *Entry) ReadSymlink(file tree.FileInfo) (string, error)

ReadSymlink returns the contents of this entry if it is a symlink.

func (*Entry) RelativePath

func (e *Entry) RelativePath() []string

RelativePath returns the path relative to the root.

func (*Entry) Remove

func (e *Entry) Remove(info tree.FileInfo) (tree.FileInfo, error)

Remove removes the specified entry, recursively.

func (*Entry) Root

func (e *Entry) Root() tree.Entry

func (*Entry) Size

func (e *Entry) Size() int64

Size returns the filesize for files, or the number of direct children for directories.

func (*Entry) String

func (e *Entry) String() string

String returns a string for debugging purposes (pretty printing).

func (*Entry) Tree

func (e *Entry) Tree() tree.Tree

Tree returns the root Entry.

func (*Entry) Type

func (e *Entry) Type() tree.Type

Type returns the file type (file, directory)

func (*Entry) UpdateFile

func (e *Entry) UpdateFile(file, source tree.FileInfo) (tree.Copier, error)

UpdateFile is part of tree.FileEntry and implements replacing a file. When closing the returned WriteCloser, the file is actually replaced.

func (*Entry) UpdateRsync

func (e *Entry) UpdateRsync(file, source tree.FileInfo) (tree.RsyncBasis, tree.Copier, error)

UpdateRsync opens the existing file to generate a signature for, and creates a new file where the new data is written, from the base file and from the patch data.

func (e *Entry) UpdateSymlink(file, source tree.FileInfo, contents string) (tree.FileInfo, tree.FileInfo, error)

UpdateSymlink sets the contents of this entry if it is a symlink.

Jump to

Keyboard shortcuts

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