Node.js Stream writable.cork() Method Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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: javascript // Node.js program to demonstrate the // writable.cork() method 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(); } }); // Writing data writable.write('hi'); // Calling cork() function writable.cork(); // Again writing some data writable.write('hello'); writable.write('world'); 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: javascript // Node.js program to demonstrate the // writable.cork() method 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(); } }); // Writing data writable.write('hi'); // Again writing some data writable.write('hello'); writable.write('world'); // Calling cork() function writable.cork(); 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 More infoAdvertise with us Next Article Node.js Stream writable.destroy() Method nidhi1352singh Follow Improve Article Tags : Web Technologies Node.js Node.js-Stream-module Similar Reads Writable Streams MethodsNode.js Stream writable.cork() MethodThe 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 ac 2 min read Node.js Stream writable.destroy() MethodThe writable.destroy() method is an inbuilt application programming interface of Stream module which is used to destroy the created stream and you cannot call the write() method to write data again after you have already destroyed the created stream. Syntax:writable.destroy()Parameters: This method 2 min read Node.js Stream writable.end() MethodThe writable.end() method is an inbuilt application programming interface of Stream module so that no more data can be written to the Writable anymore. The arguments chunk and encoding are optional which will permit one final new chunk of data to be written instantly before closing the stream. Moreo 3 min read Node.js Stream writable.setDefaultEncoding() MethodThe writable.setDefaultEncoding() method is an inbuilt application programming interface of Stream module which is used to set the default encoding for a Writable stream. Syntax: writable.setDefaultEncoding( encoding ) Parameters: This method accepts single parameter encoding which holds the encodin 2 min read Node.js Stream writable.uncork() MethodThe writable.uncork() method is an inbuilt application programming interface of Stream module which is used to flush all the buffered data when stream.cork() method was called. Syntax: writable.uncork() Parameters: This method does not accept any parameters. Return Value: If this method is being cal 2 min read Node.js Stream writable._write() MethodThe writable._write() method is an inbuilt application programming interface of Stream module which is used to implement a writable stream. The writable._write() method is affixed with an underscore as it is inside the class that defines it. Moreover, the user program must not call it directly. This 3 min read Node.js Stream writable.write() MethodThe writable.write() method is an inbuilt application programming interface of Stream module which is used to write some data to the Writable stream. The callback function is called once the data has been completely handled. Syntax: writable.write( chunk, encoding, callback) Parameters: This method 2 min read Node.js Stream readable.read() MethodThe readable.read() method is an inbuilt application programming interface of Stream module which is used to read the data out of the internal buffer. It returns data as a buffer object if no encoding is being specified or if the stream is working in object mode. Syntax: readable.read( size ) Parame 2 min read Node.js Stream readable.destroy() MethodThe readable.destroy() method is an inbuilt application programming interface of Stream module which is used to destroy the stream. Syntax: readable.destroy( error ) Parameters: This method accepts single parameter error which is optional and it emits an error while handling error event. Return Valu 2 min read Node.js Stream readable.pause() MethodThe readable.pause() method is an inbuilt application programming interface of Stream module which is used to stop the flowing mode from emitting 'data' events. If any data that becomes accessible will continue to exist in the internal buffer. Syntax: readable.pause() Parameters: This method does no 2 min read Node.js Stream readable.isPaused() MethodThe readable.isPaused() method is an inbuilt application programming interface of Stream module which is used to check the current operating state of the Readable streams. Syntax: readable.isPaused() Parameters: This method does not accept any parameters. Return Value: It returns true if the Readabl 1 min read Node.js Stream readable.resume() MethodNode.js streams are powerful tools for handling data transfer efficiently, especially when dealing with large datasets or real-time data. The readable.resume() method is a part of the readable stream interface, playing a crucial role in managing the flow of data. This article will delve into what re 4 min read Writable Streams PropertyNode.js Stream writable.writableLength PropertyThe writable.writableLength property is an inbuilt application of stream module which is used to check the number of bytes in the queue that is ready to be written. Syntax: writable.writableLength Return Value: This property returns the number of bytes that is ready to write into the queue. Below 2 min read Node.js Stream writable.writableObjectMode PropertyThe writable.writableObjectMode property in Stream module is used to get the object mode value of the Writable stream. Syntax: writable.writableObjectMode Return Value: It returns true if the objectMode is set to true otherwise returns false. Below examples illustrate the use of writable.writableObj 2 min read Node.js Stream writable.writableFinished PropertyThe writable.writableFinished property is set to true instantly before the emit of the 'finish' event. Syntax: writable.writableFinished Return Value: It returns true if 'finish' event is called before it else it returns false. Below examples illustrate the use of writable.writableFinished property 2 min read Node.js Stream writable.writableCorked PropertyThe 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 t 2 min read Node.js Stream writable.destroyed PropertyThe 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 r 2 min read Node.js Stream writable.writable PropertyThe writable.writable property is an inbuilt application programming interface of Stream module which is used to check the writable.write() method is safe to call or not. Syntax: writable.writable Return Value: It returns true if it is safe to call writable.write() method otherwise returns false. Be 2 min read Node.js Stream writable.writableEnded PropertyThe writable.writableEnded property is an inbuilt application programming interface of Stream module which is used to check the writable.end() method is being called or not. Syntax: writable.writableEnded Return Value: It returns true if writable.end() method is being called before otherwise returns 3 min read Node.js Stream writable.writableHighWaterMark PropertyThe writable.writableHighWaterMark property is an inbuilt application programming interface of stream module which is used to check the highWaterMark value which was passed while creating the Writable. Syntax: writable.writableHighWaterMark Return Value: It returns the value of highwatermark if it i 2 min read Node.js Stream readable.destroyed PropertyThe readable.destroyed property is an inbuilt application programming interface of Stream module which is used to check the readable.destroy() function is being called or not. Syntax: readable.destroyed Return Value: It returns true if readable.destroy() method is being called otherwise returns fals 2 min read Writable Streams EventNode.js stream.Writable close EventThe stream.Writable close Event is an inbuilt application programming interface of Stream module which is used to emit when the stream and any of its hidden resources (for example, a file descriptor) is being closed. This event implies that no further events will be emitted, plus no further computat 2 min read Node.js Writable Stream finish EventThe 'finish' event in a Writable Stream is emitted after the Calling of writable.end() method when all the data is being flushed to the hidden system. Syntax: Event: 'finish' Return Value: If the writable.end() method is being called before then this event is emitted else its not emitted. Below exam 2 min read Node.js Writable Stream pipe EventThe pipe event in a Writable Stream is emitted when the stream.pipe() method is being called on a readable stream by attaching this writable to its set of destinations. Syntax: Event: 'pipe' Return Value: If the pipe() method is being called then this event is emitted else it is not emitted. The b 1 min read Node.js Writable Stream unpipe EventThe 'unpipe' event in a Writable Stream is emitted when the stream.unpipe() method is being called on a Readable stream by detaching this Writable from its set of destinations. Syntax: Event: 'unpipe' Return Value: If the unpipe() method is being called then this event is emitted else it's not emit 1 min read Readable Streams MethodsNode.js Stream readable.pipe() MethodThe readable.pipe() method in a Readable Stream is used to attach a Writable stream to the readable stream so that it consequently switches into flowing mode and then pushes all the data that it has to the attached Writable. Syntax:readable.pipe( destination, options )Parameters: This method accepts 2 min read Node.js Stream readable.unpipe() MethodThe readable.unpipe() method in a Readable Stream is used to detach a Writable stream which was previously attached while using the stream.pipe() method. Syntax: readable.unpipe( destination ) Parameters: This method accepts single parameter destination which is the destination of writable stream to 1 min read Node.js Stream readable.unshift() MethodThe readable.unshift() method in a Readable Stream is utilized to push a chunk of data back into the internal buffer. However, when a stream is being fully consumed and it needs to be "un-consumed" then this method is helpful. Syntax: readable.unshift( chunk, encoding ) Parameters: This method accep 2 min read Node.js stream.Readable.from() MethodThe stream.Readable.from() method is an inbuilt application programming interface of the Stream module which is used to construct Readable Streams out of iterators. Syntax: stream.Readable.from( iterable, options ) Parameters: This method accept two parameters as mentioned above and described below: 2 min read Node.js Stream readable.setEncoding() MethodThe readable.setEncoding() method in a Readable Stream is used to set the encoding of the data read. Syntax: readable.setEncoding( encoding ) Parameters: This method accepts single parameter encoding which holds the encoding type. Return Value: It returns the data in the encoded form. Below examples 1 min read Readable Streams PropertyNode.js Stream readable.readableLength PropertyThe readable.readableLength property in a readable Stream that is used to check the number of bytes in the queue which is ready to be read. Syntax: readable.readableLength Return Values: It returns the number of bytes in the queue which are ready to be read. Below examples illustrate the use of read 1 min read Node.js Stream readable.readableHighWaterMark PropertyThe readable.readableHighWaterMark property in a readable stream that is used to check the value of highWaterMark used while constructing Readable streams. Syntax: readable.readableHighWaterMark Return Value: It returns the value of highWaterMark used while constructing Readable streams. Below examp 1 min read Node.js Stream readable.readableFlowing PropertyThe readable.readableFlowing property in a readable stream that utilized to check if the streams are in flowing mode or not. Syntax: readable.readableFlowing Return Value: It returns true if stream is in flowing mode else it returns false. Below examples illustrate the use of readable.readableFlowin 1 min read Node.js Stream readable.readableEnded PropertyThe readable.readableEnded property in a readable Stream is utilized to check if the end event is emitted or not. Syntax: readable.readableEnded Return Value: It returns true if end event is emitted else it returns false. Below examples illustrate the use of readable.readableEnded property in Node.j 2 min read Node.js Stream readable.readableObjectMode PropertyThe readable.readableObjectMode property in a Readable Stream that is used to check the objectMode of the stream. Syntax: readable.readableObjectMode Return Value: It returns the Boolean value. Below examples illustrate the use of readable.readableObjectMode property in Node.js: Example 1: javascrip 2 min read Node.js Stream readable.readable PropertyThe readable.readable property is an inbuilt application programming interface of Stream module which is used to check if it is safe to call readable.read() method. Syntax: readable.readable Return Value: It returns true if readable.read() method is being called otherwise returns false. Below exampl 1 min read Readable Streams EventsNode.js Readable Stream pause EventThe 'pause' Event in a Readable Stream is emitted when stream.pause() is being called and readableFlowing property is not false. Syntax: Event: 'pause' Return Value: It is emitted if readable.pause() is being called else it is not emitted. Below examples illustrate the use of pause event in Node.js: 1 min read Node.js Readable Stream resume EventThe 'resume' Event in a Readable Stream is emitted when stream.resume() is being called and readableFlowing property is not true. Syntax: Event: 'resume' Return Value: It is emitted if readable.resume() is being called else it is not emitted. Below examples illustrate the use of resume event in Node 2 min read Node.js Readable Stream error EventThe 'error' event in Readable stream can be emitted at any time. It takes place when the hidden stream is not able to generate data due to some hidden internal failure or when the implementation of stream pushes a chunk of data which is not valid. Moreover, a single Error object is passed as an argu 1 min read Node.js Readable Stream readable EventThe 'readable' Event in a Readable Stream is emitted when the data is available so that it can be read from the stream or it can be emitted by adding a listener for the 'readable' event which will cause data to be read into an internal buffer. Syntax: Event: 'readable' Below examples illustrate the 1 min read Node.js Readable Stream data EventThe 'data' Event in a Readable Stream is emitted when readable.pipe() and readable.resume() method is called for switching the stream into the flowing mode or by adding a listener callback to the data event. This event can also be emitted by calling readable.read() method and returning the chunk of 2 min read Node.js Readable Stream close EventThe 'close' Event in a Readable Stream is emitted when the stream and any of its hidden resources are being closed This event implies that no further events can be emitted, and no further computations can take place. Moreover, if a Readable stream is created with the emitClose option then it can alw 1 min read Node.js Readable Stream end EventThe 'end' Event in a Readable Stream is emitted when there is no available data to be consumed from the readable stream. And the 'end' event won't be emitted if the data is not fully consumed. It can be done by switching the stream into the flowing mode, or by calling stream.read() method again and 2 min read Transform Streams MethodsNode.js Stream transform.destroy() MethodThe transform.destroy() method in a Readable Stream is used to destroy the transform stream and also emits an 'error' event optionally. Moreover, the transform stream releases any internal resources after this call is made. Syntax: transform.destroy( error ) Parameters: This method accepts single p 2 min read Node.js Stream.pipeline() MethodThe stream.pipeline() method is a module method that is used to the pipe by linking the streams passing on errors and accurately cleaning up and providing a callback function when the pipeline is done. Syntax: stream.pipeline(...streams, callback) Parameters: This method accepts two parameters as m 2 min read Node.js stream.finished() MethodThe stream.finished() method is utilized to receive an alert if a stream is not writable or readable anymore or if it had experienced an error or a close event that is immature. Syntax:  stream.finished(stream, options, callback) Parameters: This method accepts three parameters as mentioned above a 3 min read Like