可读流中的可读。可读长度属性,用于检查队列中准备读取的字节数。
用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。