当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


node.js Stream writable.writableHighWaterMark用法及代码示例


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

用法:

writable.writableHighWaterMark

返回值:如果设置,它将返回高水印值,否则返回默认值。


以下示例说明了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

这里,返回在创建可写流时设置的highWaterMark的值。

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



相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Node.js | Stream writable.writableHighWaterMark Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。