📜  Node.js Stream writable.writableHighWaterMark 属性

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

Node.js Stream writable.writableHighWaterMark 属性

writable.writableHighWaterMark 属性是流模块的内置应用程序编程接口,用于检查创建 Writable 时传递的highWaterMark值。

句法:

writable.writableHighWaterMark

返回值:如果设置则返回highwatermark的值,否则返回默认值。

下面的例子说明了 Node.js 中writable.writableHighWaterMark 属性的使用:

示例 1:

// Node.js program to demonstrate the     
// writable.writableHighWaterMark Property
  
// Accessing stream module
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('GFG');
  
// Calling writable.writableHighWaterMark 
// Property
writable.writableHighWaterMark;

输出:

hi
GFG
16384

这里返回默认值。

示例 2:

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

输出:

1234

这里,返回创建 Writable 流时设置的highWaterMark的值。

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