Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js Stream readable.readableEnded Property

  • Last Updated : 12 Oct, 2021

The readable.readableEnded property in a readable Stream is utilized to check if the end event is emitted or not.

Syntax:

readable.readableEnded

Return Value: It returns true if end event is emitted else it returns false.

Below examples illustrate the use of readable.readableEnded property in Node.js:

Example 1:






// Node.js program to demonstrate the     
// readable.readableEnded Property  
  
// Include fs module
var fs = require("fs");
  
// Data to be displayed
var data = '';
  
// Create a readable stream
var readable = fs.createReadStream("input.text");
  
// Set the encoding to be utf8. 
readable.setEncoding('UTF8');
  
// Handling stream event data and end
readable.on('data', function(chunk) {
   data += chunk;
});
  
// End event
readable.on('end',function() {
   console.log(data);
});
  
// Calling readableEnded property
readable.readableEnded;

Output:

read: hello
true
end!!

Example 2:




// Node.js program to demonstrate the     
// readable.readableEnded Property  
  
// Include fs module
var fs = require("fs");
  
// Create a readable stream
var readable = fs.createReadStream("input.text");
  
// Set the encoding to be utf8. 
readable.setEncoding('UTF8');
readable.on('readable', () => {
  let chunk;
  
  // Using while loop and calling
  // read method with parameter
  while (null !== (chunk = readable.read())) {
  
    // Displaying the chunk
    console.log(`read: ${chunk}`);
  }
});
  
// Calling readableEnded property
readable.readableEnded;

Output:

false
read: hello

Reference: https://nodejs.org/api/stream.html#stream_readable_readableended.




My Personal Notes arrow_drop_up
Recommended Articles
Page :