📜  Node.js 流 readable.readableHighWaterMark 属性

📅  最后修改于: 2022-05-13 01:56:40.088000             🧑  作者: Mango

Node.js 流 readable.readableHighWaterMark 属性

可读流中的readable.readableHighWaterMark 属性,用于检查构建可读流时使用的 highWaterMark 的值。

句法:

readable.readableHighWaterMark

返回值:它返回构造可读流时使用的 highWaterMark 的值。

下面的示例说明了 Node.js 中readable.readableHighWaterMark 属性的使用:

示例 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;

输出:

65536
read: GeeksforGeeks

示例 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;

输出:

1234

参考: https://nodejs.org/api/stream.html#stream_readable_readablehighwatermark。