Open In App

Node.js Stream readable.readableHighWaterMark Property

Improve
Improve
Like Article
Like
Save
Share
Report

The 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 examples illustrate the use of readable.readableHighWaterMark property in Node.js:

Example 1:




// Node.js program to demonstrate the     
// readable.readableHighWaterMark Property  
  
// Include fs module
const fs = require("fs");
  
// Constructing readable stream
const readable = fs.createReadStream("input.txt");
  
// Instructions for reading data
readable.on('readable', () => {
  let chunk;
  
  // Using while loop and calling
  // read method with parameter
  while (null !== (chunk = readable.read())) {
  
    // Displaying the chunk
    console.log(`read: ${chunk}`);
  }
});
  
// Calling readable.readableHighWaterMark
// Property
readable.readableHighWaterMark;


Output:

65536
read: GeeksforGeeks

Example 2:




// Node.js program to demonstrate the     
// readable.readableHighWaterMark Property
   
// Accessing stream module
const stream = require('stream');
   
// Creating a stream and setting the value
// of the highWaterMark
const readable = new stream.Readable({
    highWaterMark: 1234
});
   
// Calling readable.readableHighWaterMark 
// Property
readable.readableHighWaterMark;


Output:

1234

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



Last Updated : 12 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads