Stream 中的 writable.writableObjectMode 属性在 Node.js 中
writable.writableObjectMode 属性用于获取给定可写流的 objectMode 属性。如果设置了对象模式,则该属性将返回值“true”,否则将返回值“false”。
语法
writeable.writableObjectMode
示例
创建一个名为 writableObjectMode.js 的文件,并复制以下代码段。创建文件后,使用以下命令运行此代码,如下面的示例所示 −
node writableObjectMode.js
writableObjectMode.js
// Program to demonstrate writable.writableObjectMode property // Importing the stream module const stream = require('stream'); // Setting the objectMode to true objectMode: true // Creating a data stream with writable const writable = new stream.Writable({ // Writing the data from stream write: function(chunk, encoding, next) { // Converting the data chunk to be displayed console.log(chunk.toString()); next(); } }); // Writing data - Not in the buffer queue writable.write('Welcome to TutorialsPoint !'); writable.write('SIMPLY LEARNING '); // Printing the length of the queue data console.log(writable.writableObjectMode == true);
输出
C:\home
ode>> node writableObjectMode.js Welcome to TutorialsPoint ! SIMPLY LEARNING true
示例
我们再来看一个示例。
// Program to demonstrate writable.writableObjectMode property // Importing the stream module const stream = require('stream'); // Creating a data stream with writable const writable = new stream.Writable({ // Writing the data from stream write: function(chunk, encoding, next) { // Converting the data chunk to be displayed console.log(chunk.toString()); next(); } }); // Writing data - Not in the buffer queue writable.write('Welcome to TutorialsPoint !'); writable.write('SIMPLY LEARNING '); // Printing the length of the queue data console.log(writable.writableObjectMode);
输出
C:\home
ode>> node writableObjectMode.js Welcome to TutorialsPoint ! SIMPLY LEARNING undefined Default value is undefined.
广告