Open In App

Node.js Stream readable.readableHighWaterMark Property

Last Updated : 12 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
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: JavaScript
// 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: JavaScript
// 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.

Next Article

Similar Reads