The uncork()
method is an inbuilt method in Stream module Writable
of NodeJS.
The uncork()
method is used to flush all the data that becomes part of the buffer memory when the stream.cork()
method is called.
writable.uncork()
All the corked data is flushed and can be displayed in the output. This method does not take any parameters.
Let’s look at a coding example using the .uncork()
method.
uncork()
needs to be called as many times ascork()
is called; otherwise, entire data may not be flushed.
// accessing streamconst stream = require('stream');// creating a Writable object along with a function.const writable = new stream.Writable({// Define a function to display the wrtiable datawrite: function(value, encoding, next) {// dislaying the address of data saved in memoryconsole.log(value);// displaying the actual data by converting it to stringconsole.log(value.toString());next();}});// write some datawritable.write('H');writable.write('E');writable.write('L');writable.write('L');writable.write('O');// cork() function is called, all incoming data will be// part of the buffer.writable.cork();// All incoming data is corked and part of buffer memory.writable.write('Welcome');writable.write('to');writable.write('Educative');// Calling the `uncork method, the data with their address// in printed in the console.writable.uncork();
Free Resources