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:
const stream = require( 'stream' );
const readable = new stream.Readable( "input.txt" );
readable.readableLength;
|
Output:
0
Example 2:
const fs = require( "fs" );
const readable = fs.createReadStream( "input.txt" );
readable.on( 'readable' , () => {
let chunk;
while ( null !== (chunk = readable.read())) {
console.log(`read: ${chunk.length}`);
}
});
readable.readableLength;
|
Output:
0
read: 13
Reference: https://nodejs.org/api/stream.html#stream_readable_readablelength.
Last Updated :
12 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...