file

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MetaFileMaxSize = 256 * 1024

MetaFileMaxSize defines the maximum size allowed for metadata files. This is only enforced to prevent memorybox from decoding potentially huge JSON blobs to see if they are memorybox metadata vs just regular ol' json. This value can be increased if a real world use-case dictates it.

View Source
const MetaFilePrefix = "meta-"

MetaFilePrefix controls naming for metadata files (which are named the same as the file they describe plus this prefix).

View Source
const MetaKey = "meta"

MetaKey is the key in metadata json files under which memorybox controls the content automatically.

View Source
const MetaKeyFileName = MetaKey + ".file"

MetaKeyFileName refers to the location where memorybox stores the name of the datafile that a metafile describes.

View Source
const MetaKeyImport = MetaKey + ".import"

MetaKeyImport refers to the location where memorybox stores details about when a file was imported.

View Source
const MetaKeyImportSet = MetaKeyImport + ".set"

MetaKeyImportSet refers to the location where memorybox stores details about what grouping of files a given file was imported with.

View Source
const MetaKeyImportSource = MetaKeyImport + ".source"

MetaKeyImportSource refers to the location where memorybox stores a string value that represents the original source a user supplied when putting a datafile into the store.

View Source
const MetaMemoryboxKey = MetaKey + ".memorybox"

MetaMemoryboxKey is the key under meta that is set to true to indicate the metadata belongs to memorybox.

Variables

This section is empty.

Functions

func DataNameFrom

func DataNameFrom(source string) string

DataNameFrom calculates a datafile name from a metafile name.

func IsMetaFileName

func IsMetaFileName(source string) bool

IsMetaFileName determines if a given source string is named like a metafile.

func MetaNameFrom

func MetaNameFrom(source string) string

MetaNameFrom calculates a metafile name for a data file.

func Sha256

func Sha256(source io.Reader) (string, int64, error)

Sha256 computes a sha256 message digest for a provided io.Reader.

func ValidateMeta

func ValidateMeta(bytes []byte) error

ValidateMeta determines if a given set of bytes matches the metaFile format.

Types

type File

type File struct {
	Name         string
	Source       string
	Size         int64
	LastModified time.Time
	Body         io.Reader
	Meta         *Meta
}

File is an OS and storage system agnostic representation of a file.

func New

func New(source string, body io.ReadSeeker, lastModified time.Time, hash HashFn) (*File, error)

New creates a new instance of a file and names it by hashing the content of the supplied reader.

func NewSha256

func NewSha256(source string, body io.ReadSeeker, lastModified time.Time) (*File, error)

func NewStub

func NewStub(name string, size int64, lastModified time.Time) *File

NewStub produces a file that can be instantiated with details from a stat call.

func (*File) Close

func (f *File) Close() error

Close calls close on the underlying Body (if there is one and it is needed).

func (*File) CurrentWith

func (f *File) CurrentWith(other *File) bool

CurrentWith calculates if an alternative file is considered to be "current" with this one. This is used by the sync system to determine if a file in one store should be copied to another.

func (*File) Read

func (f *File) Read(p []byte) (int, error)

Read calls read on the underlying Body (if there is one).

type HashFn

type HashFn func(io.Reader) (string, int64, error)

type List

type List []*File

List provides a listing of files that can be reasoned about with memorybox semantics. It also satisfies the sort.Sortable interface.

func (List) ByName

func (l List) ByName() map[string]*File

ByName produces a map keyed by filename of all files in the list.

func (List) Data

func (l List) Data() List

Data produces a new file list that only contains datafiles.

func (List) Filter

func (l List) Filter(fn func(*File) bool) List

Filter returns a new index where each file has been kept or discarded on based on the result of processing it with the supplied predicate function.

func (List) Invalid

func (l List) Invalid() List

Invalid returns a list of files that lack a metafile or datafile pair.

func (List) Len

func (l List) Len() int

Len returns the length of the underlying array.

func (List) Less

func (l List) Less(i, j int) bool

Less returns which of two indexes in the array is "smaller" alphanumerically.

func (List) Meta

func (l List) Meta() List

Meta produces a new file list that only contains metafiles.

func (List) Names

func (l List) Names() []string

Names produces an array of filenames in the same order as the file list.

func (List) Swap

func (l List) Swap(i, j int)

Swap re-orders the underlying array (used by sort.Sort).

func (List) Valid

func (l List) Valid() List

Valid returns a list of files have a metafile or datafile pair.

type Meta

type Meta []byte

Meta holds JSON encoded metadata.

func NewMetaFromFile

func NewMetaFromFile(file *File) *Meta

NewMetaFromFile produces memorybox formatted metadata from a supplied file.

func (Meta) DataFileName

func (m Meta) DataFileName() string

DataFileName extracts the datafile this metadata describes.

func (*Meta) Delete

func (m *Meta) Delete(key string)

Delete removes a value from the json-encoded byte array.

func (*Meta) Get

func (m *Meta) Get(key string) interface{}

Get retrieves a value from the json-encoded byte array.

func (*Meta) Merge

func (m *Meta) Merge(data string) error

Merge takes an object and assigns every key into the meta field except managed ones.

func (*Meta) Set

func (m *Meta) Set(key string, value string)

Set persists a value in the json-encoded byte array.

func (Meta) Source

func (m Meta) Source() string

Source extracts the original source of the datafile this metadata describes.

func (*Meta) String

func (m *Meta) String() string

String converts the underlying byte array string form.

Jump to

Keyboard shortcuts

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