PassThrough
The stream.PassThrough
class is a trivial implementation of a Transform
stream that simply passes the input bytes across to the output. Its purpose is
primarily for examples and testing, but there are some use cases wherestream.PassThrough
is useful as a building block for novel sorts of streams.
Properties
allowHalfOpen
booleanRequiredIf
false
then the stream will automatically end the writable side when the readable side ends. Set initially by the allowHalfOpen
constructor option, which defaults to true
. This can be changed manually to change the half-open behavior of an existingDuplex
stream instance, but must be changed before the 'end'
event is emitted.closed
booleanRequiredIs
true
after 'close'
has been emitted.destroyed
booleanRequiredIs
true
after readable.destroy()
has been called.Returns error if the stream has been destroyed with an error.
readable
booleanRequiredIs
true
if it is safe to call readable.read()
, which means the stream has not been destroyed or emitted 'error'
or 'end'
.readableAborted
booleanRequiredReturns whether the stream was destroyed or errored before emitting
'end'
.readableDidRead
booleanRequiredReturns whether
'data'
has been emitted.Getter for the property
encoding
of a given Readable
stream. The encoding
property can be set using the readable.setEncoding()
method.readableEnded
booleanRequiredBecomes
true
when 'end'
event is emitted.readableFlowing
null | booleanRequiredThis property reflects the current state of a
Readable
stream as described in the Three states
section.readableHighWaterMark
numberRequiredReturns the value of
highWaterMark
passed when creating this Readable
.readableLength
numberRequiredThis property contains the number of bytes (or objects) in the queue ready to be read. The value provides introspection data regarding the status of the
highWaterMark
.readableObjectMode
booleanRequiredGetter for the property
objectMode
of a given Readable
stream.writable
booleanRequiredIs
true
if it is safe to call writable.write()
, which means the stream has not been destroyed, errored, or ended.writableCorked
numberRequiredNumber of times
writable.uncork()
needs to be called in order to fully uncork the stream.writableEnded
booleanRequiredIs
true
after writable.end()
has been called. This property does not indicate whether the data has been flushed, for this use writable.writableFinished
instead.writableFinished
booleanRequiredIs set to
true
immediately before the 'finish'
event is emitted.writableHighWaterMark
numberRequiredReturn the value of
highWaterMark
passed when creating this Writable
.writableLength
numberRequiredThis property contains the number of bytes (or objects) in the queue ready to be written. The value provides introspection data regarding the status of the
highWaterMark
.writableNeedDrain
booleanRequiredIs
true
if the stream's buffer has been full and stream will emit 'drain'
.writableObjectMode
booleanRequiredGetter for the property
objectMode
of a given Writable
stream.Value:
Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.captureRejections
booleanRequireddefaultMaxListeners
numberRequiredBy default, a maximum of
10
listeners can be registered for any single event. This limit can be changed for individual EventEmitter
instances using the emitter.setMaxListeners(n)
method. To change the default for _all_EventEmitter
instances, the events.defaultMaxListeners
property can be used. If this value is not a positive number, a RangeError
is thrown. Take caution when setting the events.defaultMaxListeners
because the change affects _all_EventEmitter
instances, including those created before the change is made. However, calling emitter.setMaxListeners(n)
still has precedence over events.defaultMaxListeners
. This is not a hard limit. The EventEmitter
instance will allow more listeners to be added but will output a trace warning to stderr indicating that a "possible EventEmitter memory leak" has been detected. For any singleEventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to temporarily avoid this warning: js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); });
The --trace-warnings
command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with process.on('warning')
and will have the additional emitter
, type
, and count
properties, referring to the event emitter instance, the event's name and the number of attached listeners, respectively. Its name
property is set to 'MaxListenersExceededWarning'
.This symbol shall be used to install a listener for only monitoring
'error'
events. Listeners installed using this symbol are called before the regular'error'
listeners are called. Installing a listener using this symbol does not change the behavior once an'error'
event is emitted. Therefore, the process will still crash if no regular 'error'
listener is installed.Methods
[asyncDispose]
Calls readable.destroy()
with an AbortError
and returns a promise that fulfills when the stream is finished.
Returns
Promise
Promise<void>RequiredSince
v20.4.0