Stream模块中的writable.writableObjectMode属性用于获取Writable流的对象模式值。
用法:
writable.writableObjectMode
返回值:如果objectMode设置为true,则返回true,否则返回false。
以下示例说明了Node.js中writable.writableObjectMode属性的使用:
范例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
此处,未设置objectMode,因此默认情况下将其设置为false。
参考: https://nodejs.org/api/stream.html#stream_writable_writableobjectmode
相关用法
- node.js Stream writable.writableLength用法及代码示例
- node.js Stream writable.destroyed用法及代码示例
- node.js Stream writable.writableEnded用法及代码示例
- node.js Stream readable.destroyed用法及代码示例
- node.js Stream writable.writableCorked用法及代码示例
- node.js Stream writable.writableHighWaterMark用法及代码示例
- node.js Stream writable.writableFinished用法及代码示例
- node.js Stream readable.readable用法及代码示例
- node.js Stream writable.writable用法及代码示例
注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Node.js | Stream writable.writableObjectMode Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。