Open In App

Node.js Readable Stream pause Event

Last Updated : 12 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The ‘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:

Example 1:




// Node.js program to demonstrate the     
// readable pause event
  
// Including fs module
const fs = require('fs');
  
// Constructing readable stream
const readable = fs.createReadStream("input.txt");
readable.on('data', (chunk) => {
  console.log(`${chunk}`);
});
   
// Handling pause event
readable.on("pause", () => {
    console.log("pause emitted!");
});
  
// Calling pause method
readable.pause();
console.log("Program ends....");


Output:

pause emitted!
Program ends....

Example 2:




// Node.js program to demonstrate the     
// readable pause event
  
// Including fs module
const fs = require('fs');
  
// Constructing readable stream
const readable = fs.createReadStream("input.txt");
readable.on('data', (chunk) => {
  console.log(`${chunk}`);
});
   
// Handling pause event
readable.on("pause", () => {
    console.log("pause emitted!");
});
  
console.log("Program ends....");


Output:

Program ends....
GeeksforGeeks

Here, pause() method is not called so pause event is not emitted.

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



Previous Article
Next Article

Similar Reads

Node.js Readable Stream readable Event
The '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 use of readable event in Node.js: Example 1: // No
1 min read
Node.js Stream readable.pause() Method
The 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 not accept any parameters. Return Value: If this met
2 min read
Node.js Stream readable.readable Property
The 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 examples illustrate the use of readable.readable propert
1 min read
Node.js Readable Stream error Event
The '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 argument to the listener callback. Syntax: Event: 'err
1 min read
Node.js Readable Stream end Event
The '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 again until all the data is being consumed. Syntax
2 min read
Node.js Readable Stream data Event
The '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 data available. Syntax: Event: 'data' Below exampl
2 min read
Node.js Readable Stream close Event
The '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 always emit 'close' event. Syntax: Event: 'close ' Be
1 min read
Node.js Readable Stream resume Event
The '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.js: Example 1: // Node.js program to demonstrate
2 min read
Node.js Stream readable.isPaused() Method
The 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 Readable state is paused otherwise returns false. Below e
1 min read
Node.js Stream readable.destroyed Property
The 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 false. Below examples illustrate the use of readable.d
2 min read