Optional[OptionalabsoluteOptionalatimeOptionalctimeOptionaldevOptionalextendedOptionalgidOptionalglobalOptionalgnameOptionalinoOptionallinkpathOptionalmodeOptionalmtimeOptionalnlinkOptionaluidOptionalunametrue if the stream can be written
True if the stream has been aborted.
No-op setter. Stream aborted status is set via the AbortSignal provided in the constructor options.
true if this is an async stream
Set to true to make this stream async.
Once set, it cannot be unset, as this would potentially cause incorrect behavior. Ie, a sync stream can be made async, but an async stream cannot be safely made sync.
The amount of data stored in the buffer waiting to be read.
For Buffer strings, this will be the total byte length.
For string encoding streams, this will be the string character length,
according to JavaScript's string.length logic.
For objectMode streams, this is a count of the items waiting to be
emitted.
true if the stream has been forcibly destroyed
true if the 'end' event has been emitted
The BufferEncoding currently in use, or null
true if the stream is currently in a flowing state, meaning that any writes will be immediately emitted.
True if this is an objectMode stream
true if the stream is currently in a paused state
StaticisAlias for isStream
Former export location, maintained for backwards compatibility.
Asynchronous for await of iteration.
This will continue emitting all chunks until the stream terminates.
Optional[captureThe Symbol.for('nodejs.rejection') method is called in case a
promise rejection happens when emitting an event and
captureRejections is enabled on the emitter.
It is possible to use events.captureRejectionSymbol in
place of Symbol.for('nodejs.rejection').
import { EventEmitter, captureRejectionSymbol } from 'node:events';
class MyClass extends EventEmitter {
constructor() {
super({ captureRejections: true });
}
[captureRejectionSymbol](err, event, ...args) {
console.log('rejection happened for', event, 'with', err, ...args);
this.destroy(err);
}
destroy(err) {
// Tear the resource down here.
}
}
OptionalnoDrain: booleanSynchronous for of iteration.
The iteration will terminate when the internal buffer runs out, even if the stream has not yet terminated.
Return a Promise that resolves to an array of all emitted data once the stream ends.
Return a Promise that resolves to the concatenation of all emitted data once the stream ends.
Not allowed on objectMode streams.
Destroy a stream, preventing it from being used for any further purpose.
If the stream has a close() method, then it will be called on
destruction.
After destruction, any attempt to write data, read data, or emit most events will be ignored.
If an error argument is provided, then it will be emitted in an 'error' event.
Optionaler: unknownMostly identical to EventEmitter.emit, with the following
behavior differences to prevent data loss and unnecessary hangs:
If the stream has been destroyed, and the event is something other
than 'close' or 'error', then false is returned and no handlers
are called.
If the event is 'end', and has already been emitted, then the event is ignored. If the stream is in a paused or non-flowing state, then the event will be deferred until data flow resumes. If the stream is async, then handlers will be called on the next tick rather than immediately.
If the event is 'close', and 'end' has not yet been emitted, then the event will be deferred until after 'end' is emitted.
If the event is 'error', and an AbortSignal was provided for the stream, and there are no listeners, then the event is ignored, matching the behavior of node core streams in the presense of an AbortSignal.
If the event is 'finish' or 'prefinish', then all listeners will be removed after emitting the event, to prevent double-firing.
End the stream, optionally providing a final write.
See Minipass#write for argument descriptions
Optionalcb: () => voidEnd the stream, optionally providing a final write.
See Minipass#write for argument descriptions
Optionalcb: () => voidEnd the stream, optionally providing a final write.
See Minipass#write for argument descriptions
Optionalencoding: EncodingOptionalcb: () => voidReturns an array listing the events for which the emitter has registered listeners.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
Returns the number of listeners listening for the event named eventName.
If listener is provided, it will return how many times the listener is found
in the list of the listeners of the event.
The name of the event being listened for
Optionallistener: (...args: any[]) => voidThe event handler function
Returns a copy of the array of listeners for the event named eventName.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Mostly identical to EventEmitter.off
If a 'data' event handler is removed, and it was the last consumer (ie, there are no pipe destinations or other 'data' event listeners), then the flow of data will stop until there is another consumer or Minipass#resume is explicitly called.
Mostly identical to EventEmitter.on, with the following
behavior differences to prevent data loss and unnecessary hangs:
Adding a 'data' event handler will trigger the flow of data
Adding a 'readable' event handler when there is data waiting to be read will cause 'readable' to be emitted immediately.
Adding an 'endish' event handler ('end', 'finish', etc.) which has already passed will cause the event to be emitted immediately and all handlers removed.
Adding an 'error' event handler after an error has been emitted will cause the event to be re-emitted immediately with the error previously raised.
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependOnceListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
Pause the stream
Adds the listener function to the beginning of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple
times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
The name of the event.
The callback function
Adds a one-time listener function for the event named eventName to the
beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
The name of the event.
The callback function
Return a void Promise that resolves once the stream ends.
Returns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
Low-level explicit read method.
In objectMode, the argument is ignored, and one item is returned if available.
n is the number of bytes (or in the case of encoding streams,
characters) to consume. If n is not provided, then the entire buffer
is returned, or null is returned if no data is available.
If n is greater that the amount of data in the internal buffer,
then null is returned.
Optionaln: number | nullMostly identical to EventEmitter.removeAllListeners
If all 'data' event handlers are removed, and they were the last consumer (ie, there are no pipe destinations), then the flow of data will stop until there is another consumer or Minipass#resume is explicitly called.
Optionalev: EventResume the stream if it is currently in a paused state
If called when there are no pipe destinations or data event listeners,
this will place the stream in a "discarded" state, where all data will
be thrown away. The discarded state is removed if a pipe destination or
data handler is added, if pause() is called, or if any synchronous or
asynchronous iteration is started.
By default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set to
Infinity (or 0) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter, so that calls can be chained.
Fully unhook a piped destination stream.
If the destination stream was the only consumer of this stream (ie,
there are no other piped destinations or 'data' event listeners)
then the flow of data will stop until there is another consumer or
Minipass#resume is explicitly called.
Write data into the stream
If the chunk written is a string, and encoding is not specified, then
utf8 will be assumed. If the stream encoding matches the encoding of
a written string, and the state of the string decoder allows it, then
the string will be passed through to either the output or the internal
buffer without any processing. Otherwise, it will be turned into a
Buffer object for processing into the desired encoding.
If provided, cb function is called immediately before return for
sync streams, or on next tick for async streams, because for this
base class, a chunk is considered "processed" once it is accepted
and either emitted or buffered. That is, the callback does not indicate
that the chunk has been eventually emitted, though of course child
classes can override this function to do whatever processing is required
and call super.write(...) only once processing is completed.
true if the stream can be read