Node.js | Stream readable.readableLength Property
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 moduleconst stream = require('stream'); // Creating a Readable stream const readable = new stream.Readable("input.txt"); // Calling readable.readableLength // Propertyreadable.readableLength; |
Output:
0
Example 2:
// Node.js program to demonstrate the // readable.readableLength property // Include fs moduleconst fs = require("fs"); // Constructing readable streamconst readable = fs.createReadStream("input.txt"); // Instructions for reading datareadable.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 propertyreadable.readableLength; |
Output:
0 read: 13
Reference: https://nodejs.org/api/stream.html#stream_readable_readablelength.


