Node.js 中的流 writable.writableObjectMode 属性
该writable.writableObjectMode属性用于获取给定可写流的objectMode属性。如果设置了对象模式,则该属性将返回“真”,否则将返回“假”。
语法
writeable.writableObjectMode
示例
创建一个具有名称的文件-writableObjectMode.js并复制以下代码片段。创建文件后,使用以下命令运行此代码,如下例所示-
node writableObjectMode.js
writableObjectMode.js
//演示writable.writableObjectModeproperty的程序 //导入流模块 const stream = require('stream'); //将objectMode设置为true objectMode: true //创建具有可写性的数据流 const writable = new stream.Writable({ //从流中写入数据 write: function(chunk, encoding, next) { //转换要显示的数据块 console.log(chunk.toString()); next(); } }); //写入数据-不在缓冲队列中 writable.write('Welcome to nhooo !'); writable.write('SIMPLY LEARNING '); //打印队列数据的长度 console.log(writable.writableObjectMode == true);输出结果
C:\home\node>> node writableObjectMode.js Welcome to nhooo ! SIMPLY LEARNING true
示例
让我们再看一个例子。
//演示writable.writableObjectModeproperty的程序 //导入流模块 const stream = require('stream'); //创建具有可写性的数据流 const writable = new stream.Writable({ //从流中写入数据 write: function(chunk, encoding, next) { //转换要显示的数据块 console.log(chunk.toString()); next(); } }); //写入数据-不在缓冲队列中 writable.write('Welcome to nhooo !'); writable.write('SIMPLY LEARNING '); //打印队列数据的长度 console.log(writable.writableObjectMode);输出结果
C:\home\node>> node writableObjectMode.js Welcome to nhooo ! SIMPLY LEARNING undefined Default value is undefined.