VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-stream-writable-cork-method/

⇱ Node.js Stream writable.cork() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Stream writable.cork() Method

Last Updated : 28 Apr, 2025

The writable.cork() method is an inbuilt application programming interface of Stream module which is used to write every data into the buffer memory. When we use stream.uncork() or stream.end() methods then the buffer data will be flushed. 

Syntax:

writable.cork() 

Parameters: This method does not accept any parameters. 

Return Value: If this method is used then the data written after this method is not displayed in the output as these data are stored in the memory and can be again shown using some other specific methods. 

Below examples illustrate the use of writable.cork() method in Node.js: 

Example 1: 

Output:

hi

Here, in the above example the data written before cork() method is only displayed and the data written after it is corked i.e. stored in the memory. 

Example 2: 

Output

hi
hello
world

In the above example, the cork() method is written at last so, none of the data is being stored in the memory. Therefore, all the written data is displayed in the output. 

Reference: https://nodejs.org/api/stream.html#stream_writable_cork

Comment

Explore