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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。