Node.js Stream 可写. writableObjectMode 属性
原文:https://www . geesforgeks . org/node-js-stream-write-writableobjectmode-property/
流模块中的可写、可写对象模式属性用于获取可写流的对象模式值。
语法:
writable.writableObjectMode
返回值:如果对象模式设置为真,则返回真,否则返回假。
以下示例说明了在 Node.js 中使用可写.可写对象模式属性:
例 1:
// Node.js program to demonstrate the
// writable.writableObjectMode Property
// Accessing stream module
const stream = require('stream');
// Creating a stream and creating
// a write function
const writable = new stream.Writable({
// setting value of objectMode
objectMode: true,
// 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('GfG')
// Calling writable.writableObjectMode
// Property
writable.writableObjectMode;
输出:
GfG
true
例 2:
// Node.js program to demonstrate the
// writable.writableObjectMode 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('GfG')
// Calling writable.writableObjectMode
// Property
writable.writableObjectMode;
输出
GfG
false
这里对象模式没有设置,所以默认设置为假。
参考:https://nodejs . org/API/stream . html # stream _ writable _ writable object mode
版权属于:月萌API www.moonapi.com,转载请注明出处