watcher

package
v0.0.0-...-044d65f Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIPFSClient

func NewIPFSClient(projectID, projectSecret string) *http.Client

NewIPFSClient constructs an http client configured to perform basic auth on every request

Types

type CID

type CID string

CID represents an IPFS content identifier. See https://docs.ipfs.io/concepts/content-addressing/

func (CID) String

func (cid CID) String() string

type Datastore

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

Datastore wraps a distributed datastore like IPFS, but keeps all watched files up to date

func NewDatastore

func NewDatastore(sh *shell.Shell, backupLocation string, refreshInterval time.Duration) (*Datastore, error)

NewDatastore constructs a datastore with the given settings

func (*Datastore) Add

func (d *Datastore) Add(path FilePath) (files chan *File, done chan struct{}, errs chan error)

Add adds the file or directory at the given path to the store while communicating any errors that are encountered. When all files have been processed a message is published one the "done" channel

func (*Datastore) AddFile

func (d *Datastore) AddFile(path FilePath) (*File, error)

AddFile adds the file at the given path to the datastore

func (*Datastore) CID

func (d *Datastore) CID() (CID, bool)

CID returns the content indentifier for all store metadata

func (*Datastore) FindCID

func (d *Datastore) FindCID(path FilePath) (CID, bool)

FindCID returns the CID matching the given path if found

func (*Datastore) FindPath

func (d *Datastore) FindPath(cid CID) (FilePath, bool)

FindPath returns the file path matching the given CID if found

func (*Datastore) FromJSON

func (d *Datastore) FromJSON(b []byte) error

FromJSON populates the datastore with files from a JSON payload

func (*Datastore) JSON

func (d *Datastore) JSON() ([]byte, error)

JSON returns the JSON representation of the files within the store

func (*Datastore) RangeStore

func (d *Datastore) RangeStore(done func(*File) (done bool))

RangeStore iterates over all files in the store until done() returns true

func (*Datastore) RemoveFile

func (d *Datastore) RemoveFile(path FilePath) error

func (*Datastore) Start

func (d *Datastore) Start() error

Start launches the event listeners for the datastore, returning the first error returned

func (*Datastore) Stop

func (d *Datastore) Stop() error

Stop gracefully stops all event processing within the datastore

func (*Datastore) UpdateCID

func (d *Datastore) UpdateCID(cid CID)

UpdateCID updates the content identifier for the datastore

type File

type File struct {
	CID          CID      `json:"cid"`
	AbsolutePath FilePath `json:"absolute_path"`
	Watcher      *Watcher `json:"-"`
	// contains filtered or unexported fields
}

File represents a file being watched

func NewFile

func NewFile(path FilePath) (*File, error)

NewFile constructs a File, updating its properties from disk

func (*File) AssignCID

func (f *File) AssignCID(cid CID)

AssignCID updates the CID reference in the File

func (*File) Checksum

func (f *File) Checksum() ([32]byte, error)

Checksum prepares a SHA256 checksum of the file contents

func (*File) Read

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

Read reads the contents of the file, updating its current checksum

func (*File) Status

func (f *File) Status() *zync.File

Status returns the RPC format for the File

type FilePath

type FilePath string

FilePath represents a proper file path

func (FilePath) String

func (path FilePath) String() string

type Watcher

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

Watcher is a utility that can watch for updates

func NewWatcher

func NewWatcher(file *File) *Watcher

NewWatcher constructs a new watcher for the given file

func (*Watcher) Start

func (w *Watcher) Start(
	interval time.Duration,
	errs chan<- error,
	removals chan<- FilePath,
	additions chan<- FilePath,
)

Start causes the watcher to begin watching the file for changes

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stops the watcher from watching the file

Jump to

Keyboard shortcuts

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