The writable.writableCorked property is an inbuilt application programming interface of Stream module which is used to check the number of times you need to call the uncork() function so that you can fully uncork the stream.
Syntax:
writable.writableCorked
Return Value: It returns an integer value that represents the number of times writable.uncork() need to be called.
Below examples illustrate the use of writable.writableCorked 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.cork();
writable.write( 'hi' );
writable.cork();
writable.write( 'GFG' );
writable.writableCorked;
|
Output:
2
Example 2:
const stream = require( 'stream' );
const writable = new stream.Writable({
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.cork();
writable.write( 'hi' );
writable.uncork();
writable.cork();
writable.write( 'GFG' );
writable.writableCorked;
|
Output:
hi
1
In the above example we have already called uncork() function once. So in order to fully uncork the stream you need to call the uncork() function only once so, the output is one.
Reference: https://nodejs.org/api/stream.html#stream_writable_writablecorked