Node.js Stream readable.readableFlowing 属性
可读流中的readable.readableFlowing 属性,用于检查流是否处于流动模式。
句法:
readable.readableFlowing
返回值:如果流处于流动模式,则返回 true,否则返回 false。
下面的示例说明了 Node.js 中readable.readableFlowing 属性的使用:
示例 1:
// Node.js program to demonstrate the
// readable.readableFlowing Property
// Include fs module
var fs = require("fs");
var data = '';
// Create a readable stream
var readerStream = fs.createReadStream('input.txt');
// Handling data event
readerStream.on('data', function(chunk) {
data += chunk;
});
// Calling readableFlowing property
readerStream.readableFlowing;
输出:
true
示例 2:
// Node.js program to demonstrate the
// readable.readableFlowing 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.readableFlowing
// Property
readable.readableFlowing;
输出:
false
参考: https://nodejs.org/api/stream.html#stream_readable_readableflowing。