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 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