Object FSWatcher
filesystem watch object
When the call fs.watch(target)
succeeds , an object of this type is returned
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19var fs = require("fs");
var watcher = fs.watch((eventType, filename) => {
if (filename) {
console.log(filename);
// Prints: <Buffer ...>
}
});
watcher.close();
// 带回调地调用
fs.watch('./tmp', {
encoding: 'buffer'
}, (eventType, filename) => {
if (filename) {
console.log(filename);
// Prints: <Buffer ...>
}
});
inheritance relationship
static property
defaultMaxListeners
Integer, the default global maximum number of listeners
1static Integer FSWatcher.defaultMaxListeners;
member attribute
onchange
Function, query and bind "file change" event, equivalent to on("change", func);
1Function FSWatcher.onchange;
onclose
Function, query and bind the "watcher closed" event, equivalent to on("close", func);
1Function FSWatcher.onclose;
onerror
Function, query and bind the "error occurred" event, which is equivalent to on("error", func);
1Function FSWatcher.onerror;
member function
close
Close the Watcher and no longer receive corresponding file change processing events
1FSWatcher.close();
on
Bind an event handler to an object
1
2Object FSWatcher.on(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Bind an event handler to an object
1Object FSWatcher.on(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
addListener
Bind an event handler to an object
1
2Object FSWatcher.addListener(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Bind an event handler to an object
1Object FSWatcher.addListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
prependListener
Bind an event handler function to the object start
1
2Object FSWatcher.prependListener(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Bind an event handler function to the object start
1Object FSWatcher.prependListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
once
Bind a one-time event handler to the object, the one-time handler will only be triggered once
1
2Object FSWatcher.once(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Bind a one-time event handler to the object, the one-time handler will only be triggered once
1Object FSWatcher.once(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
prependOnceListener
Bind an event handler function to the object start
1
2Object FSWatcher.prependOnceListener(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Bind an event handler function to the object start
1Object FSWatcher.prependOnceListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
off
unspecify function from object processing queue
1
2Object FSWatcher.off(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Cancels all functions in the object processing queue
1Object FSWatcher.off(String ev);
Call parameters:
- ev: String, the name of the specified event
return result:
- Object, returns the event object itself, which is convenient for chain calls
unspecify function from object processing queue
1Object FSWatcher.off(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the name of the object attribute is used as the event name, and the value of the attribute is used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
removeListener
unspecify function from object processing queue
1
2Object FSWatcher.removeListener(String ev,
Function func);
Call parameters:
- ev: String, the name of the specified event
- func: Function, specifies the event handler function
return result:
- Object, returns the event object itself, which is convenient for chain calls
Cancels all functions in the object processing queue
1Object FSWatcher.removeListener(String ev);
Call parameters:
- ev: String, the name of the specified event
return result:
- Object, returns the event object itself, which is convenient for chain calls
unspecify function from object processing queue
1Object FSWatcher.removeListener(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the name of the object attribute is used as the event name, and the value of the attribute is used as the event processing function
return result:
- Object, returns the event object itself, which is convenient for chain calls
removeAllListeners
Cancels all listeners for all events from the object processing queue, or removes all listeners for the specified event if an event is specified.
1Object FSWatcher.removeAllListeners(String ev);
Call parameters:
- ev: String, the name of the specified event
return result:
- Object, returns the event object itself, which is convenient for chain calls
Cancels all listeners for all events from the object processing queue, or removes all listeners for the specified event if an event is specified.
1Object FSWatcher.removeAllListeners(Array evs = []);
Call parameters:
- evs: Array, the name of the specified event
return result:
- Object, returns the event object itself, which is convenient for chain calls
setMaxListeners
The default limit on the number of listeners, for compatibility only
1FSWatcher.setMaxListeners(Integer n);
Call parameters:
- n: Integer, specifies the number of events
getMaxListeners
Gets the default limited number of listeners, for compatibility only
1Integer FSWatcher.getMaxListeners();
return result:
- Integer, returns the default limit number
listeners
Query the array of listeners for the specified event of the object
1Array FSWatcher.listeners(String ev);
Call parameters:
- ev: String, the name of the specified event
return result:
- Array, returns an array of listeners for the specified event
listenerCount
Query the number of listeners for the specified event of the object
1Integer FSWatcher.listenerCount(String ev);
Call parameters:
- ev: String, the name of the specified event
return result:
- Integer, returns the number of listeners for the specified event
Query the number of listeners for the specified event of the object
1
2Integer FSWatcher.listenerCount(Value o,
String ev);
Call parameters:
- o: Value, specifies the object of the query
- ev: String, the name of the specified event
return result:
- Integer, returns the number of listeners for the specified event
eventNames
Query listener event name
1Array FSWatcher.eventNames();
return result:
- Array, returns an array of event names
emit
Actively trigger an event
1
2Boolean FSWatcher.emit(String ev,
...args);
Call parameters:
- ev: String, event name
- args: ..., event parameters, will be passed to the event handler function
return result:
- Boolean, returns the event trigger status, returns true if there is a response event, otherwise returns false
toString
Return the string representation of the object, generally return "[Native Object]", the object can be reimplemented according to its own characteristics
1String FSWatcher.toString();
return result:
- String, returns a string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable properties defined by the object
1Value FSWatcher.toJSON(String key = "");
Call parameters:
- key: String, not used
return result:
- Value, which returns a JSON-serializable value