Node's readable stream.
Only to be used in object mode.
- Source:
- See:
Methods
-
read() → {Object}
-
Reads the next available item.
To be repeatedly called until it returns
null
after the stream emitsreadable
.Returns:
next available item ornull
if no item is currently available.- Type
- Object
Example
stream.on('readable', function() { var item; while (null !== (item = stream.read())) { // handle item } });
Events
-
end
-
End event.
Called after all data has been read.
Example
stream.on('end', function(err) { console.log('done with my stream'); });
-
error
-
Error event.
Called if there is an error while reading data.
Type:
- Error
Example
stream.on('error', function(err) { console.error(err); });
-
readable
-
Readable event.
Notifies the stream can be read again.
Type:
- Object
Example
stream.on('readable', function() { // use stream.read() until it returns null });