Readable
Since
v0.9.4
Inheritors
Properties
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.
Functions
Event emitter The defined events on documents including:
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.
This method returns a new stream with the first limit chunks dropped from the start.
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 the current max listener value for the EventEmitter
which is either set by emitter.setMaxListeners(n)
or defaults to {@link defaultMaxListeners}.
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.
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.
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.
The readable.setEncoding()
method sets the character encoding for data read from the Readable
stream.
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.
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.)