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:
const fs = require( 'fs' );
const readable = fs.createReadStream( "input.txt" );
readable.readable;
|
Output:
true
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}`);
}
});
console.log( "Program ends!!" );
readable.readable;
|
Output:
Program ends!!
true
read: hello
Reference: https://nodejs.org/api/stream.html#stream_readable_readable
Last Updated :
12 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...