watch

package
v0.0.0-...-fd09470 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package watch provides watch events for a filesystem location.

Internally, it is using fsnotify, but provides a very different functionality. fsnotify is a platform independent abstraction of filesystem event, and watches filesystem items themselves (i.e. inode). Watch monitors a filesystem location (i.e path or filename), wether a filesystem item exists at this location or not. Key differences include:

fsnotify will return an error if the target does not exist. watch doesn't and will send a notification when a file is first created at this location.

An fsnotify object watching 'path/to/file.txt' will not fire if 'path/to' is renamed to 'path/not_to'. watch will detect that change and signal that the file has been deleted, as it is no longer present at the watched location

FileWatcher objects should be created with etiher watch.New() or watch.NewCtx().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType int

EventType represent the type of file watch event

const (
	// Created is the event type sent when the watched location is created
	Created EventType = iota + 1

	// Updated is the event type sent when the watched location is changed
	Updated

	// Deleted is the event type sent when the watched location is removed
	Deleted
)

func (EventType) String

func (e EventType) String() string

type FileWatcher

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

FileWatcher watches a single filesystem location and notifies xxx when a file at that location is created, updated or deleted

func NewFileWatcher

func NewFileWatcher(filename string) (*FileWatcher, error)

NewFileWatcher creates a new FileWatcher

func NewFileWatcherWithContext

func NewFileWatcherWithContext(ctx context.Context, filename string) (*FileWatcher, error)

NewFileWatcherWithContext creates a new FileWatcher with an explicit cancelation context

func (*FileWatcher) Close

func (w *FileWatcher) Close()

Close closes the watcher and releases associated resources

func (*FileWatcher) Info

func (w *FileWatcher) Info() os.FileInfo

Info retuens the FileInfo of the watched file, or nil if there is not file at the watched location

func (*FileWatcher) UpdateChannel

func (w *FileWatcher) UpdateChannel() <-chan EventType

UpdateChannel returns the readabl channel on which updates are sent

Jump to

Keyboard shortcuts

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