Node.js Stream writable.destroyed Property
Last Updated :
12 Oct, 2021
The writable.destroyed property is an inbuilt application programming interface of Stream module which is used to check the writable.destroy() method is being called or not.
Syntax:
writable.destroyed
Return Value: This property returns true if writable.destroy() method is called before it else it returns false.
Below examples illustrate the use of writable.destroyed 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( 'hello' );
writable.destroy();
writable.destroyed;
|
Output:
hi
hello
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( 'hello' );
writable.destroyed;
|
Output:
hi
hello
false
In the above example the output is false as writable.destroy() method is not called before calling the property writable.destroyed.
Reference: https://nodejs.org/api/stream.html#stream_writable_destroyed
Share your thoughts in the comments
Please Login to comment...