當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


node.js Stream readable.readableHighWaterMark用法及代碼示例


可讀流中的txt.properties屬性,該屬性用於檢查在構造Readable流時使用的highWaterMark的值。

用法:

readable.readableHighWaterMark

返回值:它返回在構造Readable流時使用的highWaterMark的值。


下麵的示例說明了Node.js中visible.sensitiveHighWaterMark屬性的使用:

範例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



相關用法


注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | Stream readable.readableHighWaterMark Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。