可讀流中的可讀。可讀長度屬性,用於檢查隊列中準備讀取的字節數。
用法:
readable.readableLength
返回值:它返回隊列中準備讀取的字節數。
下麵的示例說明了Node.js中visible.izableLength屬性的使用:
範例1:
// Node.js program to demonstrate the
// readable.readableLength Property
// Accessing stream module
const stream = require('stream');
// Creating a Readable stream
const readable = new stream.Readable("input.txt");
// Calling readable.readableLength
// Property
readable.readableLength;
輸出:
0
範例2:
// Node.js program to demonstrate the
// readable.readableLength 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
while (null !== (chunk = readable.read())) {
// Displaying the chunk length
console.log(`read:${chunk.length}`);
}
});
// Calling readableLength property
readable.readableLength;
輸出:
0 read:13
參考: https://nodejs.org/api/stream.html#stream_readable_readablelength。
相關用法
- node.js Stream writable.writableHighWaterMark用法及代碼示例
- node.js Stream readable.readableObjectMode用法及代碼示例
- node.js Stream writable.writableFinished用法及代碼示例
- node.js Stream writable.writableObjectMode用法及代碼示例
- node.js Stream writable.writableLength用法及代碼示例
- node.js Stream readable.readableHighWaterMark用法及代碼示例
- node.js Stream writable.writableEnded用法及代碼示例
- node.js Stream writable.destroyed用法及代碼示例
- node.js Stream readable.destroyed用法及代碼示例
- node.js Stream readable.readableEncoding用法及代碼示例
- node.js Stream readable.readableEnded用法及代碼示例
- node.js Stream writable.writableCorked用法及代碼示例
- node.js Stream readable.readableFlowing用法及代碼示例
- node.js Stream writable.writable用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | Stream readable.readableLength Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。