Node.js Stream writable.writable Property
Last Updated :
12 Oct, 2021
The writable.writable property is an inbuilt application programming interface of Stream module which is used to check the writable.write() method is safe to call or not.
Syntax:
writable.writable
Return Value: It returns true if it is safe to call writable.write() method otherwise returns false.
Below examples illustrate the use of writable.writable property in Node.js:
Example 1:
const stream = require( 'stream' );
const writable = new stream.Writable({
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.write( 'hi' );
writable.write( 'GFG' );
writable.writable;
|
Output:
hi
GFG
true
Example 2:
const stream = require( 'stream' );
const writable = new stream.Writable({
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.write( 'hi' );
writable.write( 'GFG' );
writable.end();
writable.writable;
|
Output:
hi
GFG
false
In the above example the output is false because the writable.end() method is called before calling the writable.writable property, so it is not safe to call writable.write() method so the output is false.
Reference: https://nodejs.org/api/stream.html#stream_writable_writable
Share your thoughts in the comments
Please Login to comment...