Open In App
Related Articles

Node.js Stream writable.writableCorked Property

Improve Article
Improve
Save Article
Save
Like Article
Like

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:




// Node.js program to demonstrate the     
// writable.writableCorked Property
  
// Accessing stream module
const stream = require('stream');
  
// Creating a stream and creating 
// a write function
const writable = new stream.Writable({
  
  // Write function with its 
  // parameters
  write: function(chunk, encoding, next) {
  
    // Converting the chunk of
    // data to string
    console.log(chunk.toString());
    next();
  }
});
  
// Calling cork function
writable.cork();
  
// Writing data
writable.write('hi');
  
// Again calling cork function
writable.cork();
  
// Again writing some data
writable.write('GFG');
  
// Calling writable.writableCorked 
// Property
writable.writableCorked;

Output:

2

Example 2:




// Node.js program to demonstrate the     
// writable.writableCorked Property
  
// Accessing stream module
const stream = require('stream');
  
// Creating a stream and creating 
// a write function
const writable = new stream.Writable({
  
  // Write function with its 
  // parameters
  write: function(chunk, encoding, next) {
  
    // Converting the chunk of
    // data to string
    console.log(chunk.toString());
    next();
  }
});
  
// Calling cork function
writable.cork();
  
// Writing data
writable.write('hi');
  
// Calling uncork() function
writable.uncork();
  
// Again calling cork function
writable.cork();
  
// Again writing some data
writable.write('GFG');
  
// Calling writable.writableCorked 
// Property
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


Last Updated : 12 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials