readStream.isRaw属性是tty模块中ReadStream类的内置应用程序编程接口,用于检查当前是否将读取流对象配置为作为原始设备运行。
用法:
const status = ReadStream.isRaw;
返回值:当且仅当当前将读取流对象配置为作为原始设备运行时,此属性才返回true。
范例1: 文件名:index.js
// Node.js program to demonstrate the
// readStream.isRaw property
// Importing dgram module
var dgram = require('dgram');
// Creating and initializing client
// and server socket
var client = dgram.createSocket("udp4");
var server = dgram.createSocket("udp4");
// Catching the message event
server.on("message", function (msg) {
// Creating and initializing a
// ReadStream object
let ReadStream = process.stdin;
// Checking if it is configured or
// not by using isRaw() method
const status = ReadStream.isRaw;
// Displaying the result
if (status) {
process.stdout.write(msg
+ "configured" + "\n");
} else {
process.stdout.write(msg
+ "not configured" + "\n");
}
// Exiting process
process.exit();
})
// Binding server with port
.bind(1234, () => {
});
// Client sending message to server
client.send("It is ", 0, 7, 1234, "localhost");
输出:
It is not configured
范例2: 文件名:index.js
// Node.js program to demonstrate the
// readStream.isRaw property
// Creating and initializing a
// ReadStream object
let ReadStream = process.stdin;
// Setting the read stream Raw mode
// by using setRawMode() method
ReadStream.setRawMode(true);
// Checking if it is configured or not
// by using isRaw() method
const status = ReadStream.isRaw;
// Displaying the result
if(status) {
console.log("It is configured");
} else {
console.log("it is not configured");
}
使用以下命令运行index.js文件:
node index.js
输出:
It is configured
参考:https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_readstream_israw
相关用法
- Node.js GM charcoal()用法及代码示例
- Node.js GM blur()用法及代码示例
- Node.js GM sharpen()用法及代码示例
- Node.js GM drawLine()用法及代码示例
- Node.js GM drawArc()用法及代码示例
- Node.js GM drawPolyline()用法及代码示例
- Node.js GM drawBezier()用法及代码示例
- Node.js GM drawCircle()用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js readStream.isRaw Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。