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.
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP