ProcessStderr
Properties
If 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 property is only present if the family autoselection algorithm is enabled in socket.connect(options)
and it is an array of the addresses that have been attempted.
This property shows the number of characters buffered for writing. The buffer may contain strings whose length after encoding is not yet known. So this number is only an approximation of the number of bytes in the buffer.
The amount of bytes sent.
If true
, socket.connect(options[, connectListener])
was called and has not yet finished. It will stay true
until the socket becomes connected, then it is set to false
and the 'connect'
event is emitted. Note that the socket.connect(options[, connectListener])
callback is a listener for the 'connect'
event.
The string representation of the local IP address the remote client is connecting on. For example, in a server listening on '0.0.0.0'
, if a client connects on '192.168.1.1'
, the value of socket.localAddress
would be'192.168.1.1'
.
The string representation of the local IP family. 'IPv4'
or 'IPv6'
.
See writable.destroyed
for further details.
Returns whether the stream was destroyed or errored before emitting 'end'
.
Returns whether 'data'
has been emitted.
Getter for the property encoding
of a given Readable
stream. The encoding
property can be set using the {@link setEncoding} method.
Becomes true
when 'end'
event is emitted.
This property reflects the current state of a Readable
stream as described in the Three states section.
Returns the value of highWaterMark
passed when creating this Readable
.
This 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
.
Getter for the property objectMode
of a given Readable
stream.
Is true
if it is safe to call writable.write()
, which means the stream has not been destroyed, errored, or ended.
This property represents the state of the connection as a string.
The string representation of the remote IP address. For example,'74.125.127.100'
or '2001:4860:a005::68'
. Value may be undefined
if the socket is destroyed (for example, if the client disconnected).
The string representation of the remote IP family. 'IPv4'
or 'IPv6'
. Value may be undefined
if the socket is destroyed (for example, if the client disconnected).
The numeric representation of the remote port. For example, 80
or 21
. Value may be undefined
if the socket is destroyed (for example, if the client disconnected).
Number of times writable.uncork()
needs to be called in order to fully uncork the stream.
Is true
after writable.end()
has been called. This property does not indicate whether the data has been flushed, for this use writable.writableFinished
instead.
Is set to true
immediately before the 'finish'
event is emitted.
Return the value of highWaterMark
passed when creating this Writable
.
This 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
.
Is true
if the stream's buffer has been full and stream will emit 'drain'
.
Getter for the property objectMode
of a given Writable
stream.
Functions
Alias for emitter.on(eventName, listener)
.
events.EventEmitter
This method returns a new stream with chunks of the underlying stream paired with a counter in the form [index, chunk]
. The first index value is 0
and it increases by 1 for each chunk produced.
writeStream.clearScreenDown()
clears this WriteStream
from the current cursor down.
Initiate a connection on a given socket.
Destroy the stream. Optionally emit an 'error'
event, and emit a 'close'
event (unless emitClose
is set to false
). After this call, the readable stream will release any internal resources and subsequent calls to push()
will be ignored.
Destroys the socket after all data is written. If the finish
event was already emitted the socket is destroyed immediately. If the socket is still writable it implicitly calls socket.end()
.
This method returns a new stream with the first limit chunks dropped from the start.
Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments to each.
Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.
Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbol
s.
This method is similar to Array.prototype.every
and calls fn on each chunk in the stream to check if all awaited return values are truthy value for fn. Once an fn call on a chunk await
ed return value is falsy, the stream is destroyed and the promise is fulfilled with false
. If all of the fn calls on the chunks return a truthy value, the promise is fulfilled with true
.
This method allows filtering the stream. For each chunk in the stream the fn function will be called and if it returns a truthy value, the chunk will be passed to the result stream. If the fn function returns a promise - that promise will be await
ed.
This method is similar to Array.prototype.find
and calls fn on each chunk in the stream to find a chunk with a truthy value for fn. Once an fn call's awaited return value is truthy, the stream is destroyed and the promise is fulfilled with value for which fn returned a truthy value. If all of the fn calls on the chunks return a falsy value, the promise is fulfilled with undefined
.
This method returns a new stream by applying the given callback to each chunk of the stream and then flattening the result.
This method allows iterating a stream. For each chunk in the stream the fn function will be called. If the fn function returns a promise - that promise will be await
ed.
Returns:
Returns the current max listener value for the EventEmitter
which is either set by emitter.setMaxListeners(n)
or defaults to {@link defaultMaxListeners}.
writeStream.getWindowSize()
returns the size of the TTY corresponding to this WriteStream
. The array is of the type [numColumns, numRows]
where numColumns
and numRows
represent the number of columns and rows in the corresponding TTY.
Returns true
if the writeStream
supports at least as many colors as provided in count
. Minimum support is 2 (black and white).
The iterator created by this method gives users the option to cancel the destruction of the stream if the for await...of
loop is exited by return
, break
, or throw
, or if the iterator should destroy the stream if the stream emitted an error during iteration.
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.
Returns a copy of the array of listeners for the event named eventName
.
This method allows mapping over the stream. The fn function will be called for every chunk in the stream. If the fn function returns a promise - that promise will be await
ed before being passed to the result stream.
writeStream.moveCursor()
moves this WriteStream
's cursor relative to its current position.
Alias for emitter.removeListener()
.
Adds the listener
function to the end 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.
Adds a one-time listener
function for the event named eventName
. The next time eventName
is triggered, this listener is removed and then invoked.
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.
Adds a one-timelistener
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.
Returns a copy of the array of listeners for the event named eventName
, including any wrappers (such as those created by .once()
).
The readable.read()
method reads data out of the internal buffer and returns it. If no data is available to be read, null
is returned. By default, the data is returned as a Buffer
object unless an encoding has been specified using the readable.setEncoding()
method or the stream is operating in object mode.
This method calls fn on each chunk of the stream in order, passing it the result from the calculation on the previous element. It returns a promise for the final value of the reduction.
Removes all listeners, or those of the specified eventName
.
Removes the specified listener
from the listener array for the event named eventName
.
Close the TCP connection by sending an RST packet and destroy the stream. If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected. Otherwise, it will call socket.destroy
with an ERR_SOCKET_CLOSED
Error. If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an ERR_INVALID_HANDLE_TYPE
Error.
The writable.setDefaultEncoding()
method sets the default encoding
for a Writable
stream.
Set the encoding for the socket as a Readable Stream
. See readable.setEncoding()
for more information.
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
By default EventEmitter
s 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.
Enable/disable the use of Nagle's algorithm.
Sets the socket to timeout after timeout
milliseconds of inactivity on the socket. By default net.Socket
do not have a timeout.
This method is similar to Array.prototype.some
and calls fn on each chunk in the stream until the awaited return value is true
(or any truthy value). Once an fn call on a chunk await
ed return value is truthy, the stream is destroyed and the promise is fulfilled with true
. If none of the fn calls on the chunks return a truthy value, the promise is fulfilled with false
.
This method returns a new stream with the first limit chunks.
This method allows easily obtaining the contents of a stream.
The readable.unpipe()
method detaches a Writable
stream previously attached using the {@link pipe} method.
Passing chunk
as null
signals the end of the stream (EOF) and behaves the same as readable.push(null)
, after which no more data can be written. The EOF signal is put at the end of the buffer and any buffered data will still be flushed.
Prior to Node.js 0.10, streams did not implement the entire node:stream
module API as it is currently defined. (See Compatibility
for more information.)
Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.
The writable.write()
method writes some data to the stream, and calls the supplied callback
once the data has been fully handled. If an error occurs, the callback
will be called with the error as its first argument. The callback
is called asynchronously and before 'error'
is emitted.