db

package
v0.0.0-...-a1d2bbf Latest Latest
Warning

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

Go to latest
Published: May 5, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Db represents a connection to leveldb
	Db *leveldb.DB
)

Functions

func CloseDb

func CloseDb()

CloseDb is a wrapper to leveldb Close func

func Get

func Get(k []byte) ([]byte, error)

Get is a wrapper to leveldb Get func

func InitDb

func InitDb() error

InitDb initialize the global Db instance located at (HOME_PATH/.orbit-drive/datastore)

func Put

func Put(k []byte, v []byte) error

Put is a wrapper to leveldb Put func

Types

type Source

type Source struct {
	// Src represents the ipfs hash of the file.
	Src string `json:"src"`

	// Size represents the size of the file.
	Size int64 `json:"size"`

	// Checksum represents the md5 checksum hash of file.
	Checksum string `json:"checksum"`
}

Source represents the meta data of a file stored locally.

func NewSource

func NewSource(path string) *Source

NewSource generates a new source instance from a given path and validates the path, computes the file checksum and size.

func (*Source) DeepCopy

func (s *Source) DeepCopy() *Source

DeepCopy deep copies a source instance and return a new instance.

func (Source) GetSrc

func (s Source) GetSrc() string

GetSrc is a getter for Source src.

func (*Source) IsNew

func (s *Source) IsNew() bool

IsNew check is the Source src is a non zero value.

func (*Source) IsSame

func (s *Source) IsSame(c *Source) bool

IsSame check if the 2 sources are the same.

func (*Source) Save

func (s *Source) Save(k []byte) error

Save write the Source instance to the db.

func (*Source) SetSrc

func (s *Source) SetSrc(src string)

SetSrc is a setter for Source src.

type Sources

type Sources map[string]*Source

Sources represents the store of the locally saved files.

func GetSources

func GetSources() (Sources, error)

GetSources iterates through db, populate and return Sources.

func (Sources) Dump

func (s Sources) Dump() error

Dump batch deletes all the entries in the mapping.

func (Sources) ExtractSource

func (s Sources) ExtractSource(k string) *Source

ExtractSource look for and return a copy of Source and deletes the key from the mapping.

func (Sources) Save

func (s Sources) Save() error

Save batch put all the entries in the mapping.

Jump to

Keyboard shortcuts

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