External: Readable

Readable

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 emits readable.

Source:
Returns:
next available item or null 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.

Source:
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
Source:
Example
stream.on('error', function(err) {
  console.error(err);
});

readable

Readable event.

Notifies the stream can be read again.

Type:
  • Object
Source:
Example
stream.on('readable', function() {
  // use stream.read() until it returns null
});