Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js Stream readable.readableLength Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The readable.readableLength property in a readable Stream that is used to check the number of bytes in the queue which is ready to be read.

Syntax:

readable.readableLength

Return Values: It returns the number of bytes in the queue which are ready to be read.

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

Example 1:




// Node.js program to demonstrate the     
// readable.readableLength Property
   
// Accessing stream module
const stream = require('stream');
   
// Creating a Readable stream 
const readable = new stream.Readable("input.txt");
   
// Calling readable.readableLength 
// Property
readable.readableLength;

Output:

0

Example 2:




// Node.js program to demonstrate the     
// readable.readableLength 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 length
    console.log(`read: ${chunk.length}`);
     }
});
  
// Calling readableLength property
readable.readableLength;

Output:

0
read: 13

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


My Personal Notes arrow_drop_up
Last Updated : 12 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials