vfs

package
v0.0.0-...-db2f6b3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxHeaderNameLength  = 256
	MaxHeaderValueLength = 10 * 1024 // 10 KiB
)
View Source
const (
	DefaultProtocol     = "0.1"
	DefaultFilePartSize = 1 << 20 // (1 MiB) – default file part size

	MaxPathLength        = 255
	MaxPathNameLength    = 50
	MaxPathLevels        = 6
	MaxPathDirFilesCount = 1024
)

Variables

View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrTooManyFiles = errors.New("too many files")
)

Functions

func IsValidPath

func IsValidPath(path string) bool

IsValidPath says the path is valid

func ValidateHeader

func ValidateHeader(h Header) error

func VersionIsGreater

func VersionIsGreater(a, b Header) bool

VersionIsGreater checks that the version of header A is higher than the version of header B

Types

type Commit

type Commit struct {
	Headers []Header
	Body    io.ReadCloser
}

func MakeCommit

func MakeCommit(vfs VFS, prv crypto.PrivateKey, src fs.FS, ts time.Time) (commit *Commit, err error)

func (*Commit) BodySize

func (c *Commit) BodySize() (n int64)

func (*Commit) Hash

func (c *Commit) Hash() []byte

func (*Commit) Root

func (c *Commit) Root() Header

func (*Commit) Trace

func (c *Commit) Trace()

func (*Commit) Updated

func (c *Commit) Updated() time.Time

func (*Commit) Ver

func (c *Commit) Ver() int64
type Header []HeaderField

func NewRootHeader

func NewRootHeader(pub crypto.PublicKey) (h Header)

func (*Header) Add

func (h *Header) Add(key, value string)

func (*Header) AddBytes

func (h *Header) AddBytes(key string, value []byte)

func (*Header) AddInt

func (h *Header) AddInt(key string, value int64)

func (*Header) AddTime

func (h *Header) AddTime(key string, value time.Time)

func (Header) Copy

func (h Header) Copy() Header

func (Header) Created

func (h Header) Created() time.Time

func (*Header) Delete

func (h *Header) Delete(key string)

func (Header) Deleted

func (h Header) Deleted() bool

func (Header) FileMerkle

func (h Header) FileMerkle() []byte

func (Header) FileSize

func (h Header) FileSize() int64

func (Header) Get

func (h Header) Get(key string) string

func (Header) GetBytes

func (h Header) GetBytes(key string) []byte

func (Header) GetInt

func (h Header) GetInt(key string) int64

func (Header) GetTime

func (h Header) GetTime(key string) time.Time

func (Header) Has

func (h Header) Has(key string) bool

func (Header) Hash

func (h Header) Hash() []byte

func (Header) IsDir

func (h Header) IsDir() bool

func (Header) IsFile

func (h Header) IsFile() bool

func (Header) Length

func (h Header) Length() (n int)

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (Header) PartSize

func (h Header) PartSize() int64

func (Header) Path

func (h Header) Path() string

func (Header) Protocol

func (h Header) Protocol() string

Protocol returns VFS-Protocol

func (Header) PublicKey

func (h Header) PublicKey() crypto.PublicKey

func (*Header) Set

func (h *Header) Set(key, value string)

func (*Header) SetBytes

func (h *Header) SetBytes(key string, value []byte)

func (*Header) SetInt

func (h *Header) SetInt(key string, value int64)

func (*Header) SetPublicKey

func (h *Header) SetPublicKey(pub crypto.PublicKey)

func (*Header) SetTime

func (h *Header) SetTime(key string, value time.Time)

func (*Header) Sign

func (h *Header) Sign(prv crypto.PrivateKey)

func (Header) String

func (h Header) String() string

func (Header) TreeMerkleRoot

func (h Header) TreeMerkleRoot() []byte

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(data []byte) (err error)

func (Header) Updated

func (h Header) Updated() time.Time

func (Header) Ver

func (h Header) Ver() int64

Ver returns last file or dir-version. batch-version

func (Header) Verify

func (h Header) Verify() bool

type HeaderField

type HeaderField struct {
	Name  string //
	Value []byte //
}

type VFS

type VFS interface {

	// FileHeader returns Header of file or directory
	FileHeader(path string) (Header, error)

	// FileMerkleProof returns hash and merkle-proof for file or dir-header
	FileMerkleProof(path string) (hash, proof []byte, err error)

	// FileParts returns hashes of file-parts
	FileParts(path string) (hashes [][]byte, err error)

	// OpenAt opens file as descriptor
	OpenAt(path string, offset int64) (io.ReadCloser, error)

	// ReadDir returns headers of directory files
	ReadDir(path string) ([]Header, error)

	// GetCommit makes commit starting from the given version
	GetCommit(ver int64) (*Commit, error)

	Get(request string) (*Commit, error)

	// Commit applies a commit
	Commit(*Commit) error
}

VFS is Virtual File System

func OpenVFS

func OpenVFS(pub crypto.PublicKey, db db.Storage) (_ VFS, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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