Node.js | Stream readable.readable Property

The readable.readable property is an inbuilt application programming interface of Stream module which is used to check if it is safe to call readable.read() method.

Syntax:

readable.readable

Return Value: It returns true if readable.read() method is being called otherwise returns false.

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

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the     
// readable.readable Property
  
// Include fs module
const fs = require('fs');
  
// Creating readable stream
const readable = fs.createReadStream("input.txt");
  
// Calling readable property
readable.readable;

chevron_right


Output:

true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the     
// readable.readable Property  
  
// Include fs module
const fs = require("fs");
  
// Constructing readable stream
const readable = fs.createReadStream("input.txt");
  
// Instructions for reading data
readable.on('readable', () => {
  let chunk;
  
  // Using while loop and calling
  // read method
  while (null !== (chunk = readable.read())) {
  
    // Displaying the chunk
    console.log(`read: ${chunk}`);
  }
});
  
// Shows that the program
// ended
console.log("Program ends!!");
  
// Calling readable property
readable.readable;

chevron_right


Output:

Program ends!!
true
read: hello

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




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.