OpenVeo Publish server

API Docs for: 8.0.0
Show:

DirectoryFsWatcher

Summary

Defines a directory watcher which is a wrapper around Node.js fs.watch.

fs.watch only emit "change" and "rename" events, nothing more. This class intends to make it more user friendly by emitting more understandable events like "create" or "delete".

It analyzes only "rename" events, "change" events are not constant between Linux and Windows systems. On both Linux and Windows systems : When a file is added a "rename" event is emitted followed by a "change" event When a file is renamed a "rename" event is emitted twice (one for the removal and one for the addition) When a file is removed a "rename" event is emitted

To work through this behaviour, a snapshot of the directory is made each time a "rename" event is fired. Then new resources inside the directory are compared to the snapshot to find out which resource has been added or removed.

If a "rename" event is emitted while the directory is being analyzed, directory will be analyzed again making every "rename" event count.

Constructor

DirectoryFsWatcher

Syntax

DirectoryFsWatcher

(
  • directoryPath
  • [options]
)

Summary

Parameters:

  • directoryPath Array

    The absolute path of the directory to watch

  • [options] Object optional

    Watcher options

    • [stabilityThreshold] Number optional

      Number of milliseconds to wait before considering a file as stable

Methods

awaitWriteFinish

Syntax

awaitWriteFinish

(
  • resourcePath
  • [lastStat]
)
private

Summary

Waits for the resource to be fully written.

Parameters:

  • resourcePath String

    The absolute path of the resource to wait for

  • [lastStat] fs.Stats optional

    Last information about the resource

close

Syntax

close

()

Summary

Stops watching the directory.

interpretRename

Syntax

interpretRename

() private async

Summary

Interprets a "rename" event.

If "rename" event corresponds to an addition, a "create" event will be fired. If "rename" event corresponds to a removal, a "delete" event will be fired.

watch

Syntax

watch

(
  • callback
)
async

Summary

Watches the directory.

Parameters:

  • callback Function

    The function to call when its starts listening to changes

    • Error An error if something went wrong

Properties

directoryPath

Syntax

directoryPath

String final

Summary

The absolute path of the watched directory.

fsWatcher

Syntax

fsWatcher

fs.FSWatcher

Summary

The Node.js directory watcher.

options

Syntax

options

Object final

Summary

Watcher options.

pendingEventsCounter

Syntax

pendingEventsCounter

Number

Summary

The number of "rename" events which haven't been treated yet.

snapshot

Syntax

snapshot

Object

Summary

The resources inside the directory with the resource path as the key and true as the value.

The snapshot represents the current content of the directory and will be updated after each "rename" event.

Events

create

Syntax

create

Summary

Fired when a new resource (file or directory) has been added to the directory.

Event Payload:

  • Path String

    of the added resource

delete

Syntax

delete

Summary

Fired when a resource (file or directory) has been deleted from the directory.

Event Payload:

  • Path String

    of the resource before it has been removed

error

Syntax

error

Summary

Fired when an error occurred.

Event Payload: