Node.js | Stream readable.readableEnded Property

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;

chevron_right


Output:

read: hello
true
end!!

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;

chevron_right


Output:

false
read: hello

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.