What does the _read function do for readable streams in nodejs?

I read the docs and there is this description, but I don't understand what it means.

All Readable stream implementations must provide a _read method to retrieve data from the main resource.

This method is prefixed with an underscore because it is internal to the class that defines it and should not be called directly by user programs. However, you must override this method in your own extension classes.

When data is available, push it to the read queue by calling readable.push (chunk). If push returns false, then you must stop reading. When _read is called again, you should start pushing more data.

What is the main resource? When you actually specify the _read function, what does it mean what purpose does it serve?

+3


source to share


1 answer


The function is _read()

used to notify a readable stream that it has highWaterMark

not been reached and that the stream may not read more data from the underlying resource. The argument passed to _read()

is a suggestion of the number of bytes (or cardinality in case objectMode

) to read from the underlying resource.



The main resource mentioned in the documentation applies to any data source. It can be anything, including another Readable stream, or it can be data that you generate dynamically (for example, a Readable stream that provides random binary data).

+3


source







All Articles